
Lab 3 Build a #VPC on #AWS
Published at : September 12, 2021
Objectives:
• To get familiar with networking services on AWS
• To learn how to create VPC, subnets, and define route tables
• To learn how to deploy and access EC2 instances in different subnets
Data:
• Copy the user_data_for_ec2 from https://github.com/xbwei/data-analysis-aws/blob/master/user_data_for_EC2
Steps:
1. Log into AWS Educate https://aws.amazon.com/education/awseducate/.
2. Find the “Cloud Computer on AWS” and then click Go to the classroom in the My Classrooms section.
3. Optional: make sure you have PuTTy https://www.putty.org/ installed on your local computer.
4. Optional: make sure you have WinSCP https://winscp.net/eng/index.php installed on your local computer
5. Create a VPC:
o IPv4 CIDR block: 10.0.0.0/16
o Enable DNS Hostnames
6. Create two subnets in the VPC created in Step5
o One public subnet
IPv4 CIDR block: 10.0.0.0/24
AZ: US-East-1a
o One private subnet
IPv4 CIDR block: 10.0.1.0/24
AZ: US-East-1b
7. Create an Internet Gateway, attached it to the VPC created in Step5.
8. Create two route tables:
o One public table:
Allow 10.0.0.0/16 to local
Allow 0.0.0.0/0 to the Internet Gateway created in Step7
Associated this table to the public subnet
o One private table:
Allow 10.0.0.0/16 to local
Associated this table to the private subnet
9. Launch your EC2 instances
o Public instance
In AWS Console, search and choose EC2;
On the EC2 page, launch an EC2 instance;
Choose the Amazon Linux (Free tier eligible)
Select the t2.micro instance type
On the Configure Instance page:
• Choose the selected VCP
• Choose the public subnet
• Enable Auto-assign Public IP
• Copy the user_data_for_ec2 code to the User Data.
In the security group, open 22 port and 80 port
Keep other settings as default.
Download the key pair to your local computer and launch your instance.
o Private instance
In AWS Console, search and choose EC2;
On the EC2 page, launch an EC2 instance;
Choose the Amazon Linux (Free tier eligible)
Select the t2.micro instance type
On the Configure Instance page:
• Choose the selected VCP
• Choose the private subnet
• Enable Auto-assign Public IP
• Copy the user_data_for_ec2 code to the User Data.
In the security group, open 22 port and 80 port
Keep other settings as default.
Select the same key pair and launch your instance.
10. Access the EC2 instances
o Open the public DNS of the instance in the public subnet.
Take a screenshot of the website
o Open the public DNS of the instance in the private subnet.
o Use WinSCP to transfer the EC2 key to the instance in the public subnet.
o SSH the instance in the public subnet. (Check lab2 video: https://youtu.be/oa2hXUYGjm8 )
o In the public instance, type the following commands:
chmod 400 your_key.pem
ssh -i ./your_key.pem ec2-user@hostname_of_private_instance
o You can now access the private instance via the public instance
• To get familiar with networking services on AWS
• To learn how to create VPC, subnets, and define route tables
• To learn how to deploy and access EC2 instances in different subnets
Data:
• Copy the user_data_for_ec2 from https://github.com/xbwei/data-analysis-aws/blob/master/user_data_for_EC2
Steps:
1. Log into AWS Educate https://aws.amazon.com/education/awseducate/.
2. Find the “Cloud Computer on AWS” and then click Go to the classroom in the My Classrooms section.
3. Optional: make sure you have PuTTy https://www.putty.org/ installed on your local computer.
4. Optional: make sure you have WinSCP https://winscp.net/eng/index.php installed on your local computer
5. Create a VPC:
o IPv4 CIDR block: 10.0.0.0/16
o Enable DNS Hostnames
6. Create two subnets in the VPC created in Step5
o One public subnet
IPv4 CIDR block: 10.0.0.0/24
AZ: US-East-1a
o One private subnet
IPv4 CIDR block: 10.0.1.0/24
AZ: US-East-1b
7. Create an Internet Gateway, attached it to the VPC created in Step5.
8. Create two route tables:
o One public table:
Allow 10.0.0.0/16 to local
Allow 0.0.0.0/0 to the Internet Gateway created in Step7
Associated this table to the public subnet
o One private table:
Allow 10.0.0.0/16 to local
Associated this table to the private subnet
9. Launch your EC2 instances
o Public instance
In AWS Console, search and choose EC2;
On the EC2 page, launch an EC2 instance;
Choose the Amazon Linux (Free tier eligible)
Select the t2.micro instance type
On the Configure Instance page:
• Choose the selected VCP
• Choose the public subnet
• Enable Auto-assign Public IP
• Copy the user_data_for_ec2 code to the User Data.
In the security group, open 22 port and 80 port
Keep other settings as default.
Download the key pair to your local computer and launch your instance.
o Private instance
In AWS Console, search and choose EC2;
On the EC2 page, launch an EC2 instance;
Choose the Amazon Linux (Free tier eligible)
Select the t2.micro instance type
On the Configure Instance page:
• Choose the selected VCP
• Choose the private subnet
• Enable Auto-assign Public IP
• Copy the user_data_for_ec2 code to the User Data.
In the security group, open 22 port and 80 port
Keep other settings as default.
Select the same key pair and launch your instance.
10. Access the EC2 instances
o Open the public DNS of the instance in the public subnet.
Take a screenshot of the website
o Open the public DNS of the instance in the private subnet.
o Use WinSCP to transfer the EC2 key to the instance in the public subnet.
o SSH the instance in the public subnet. (Check lab2 video: https://youtu.be/oa2hXUYGjm8 )
o In the public instance, type the following commands:
chmod 400 your_key.pem
ssh -i ./your_key.pem ec2-user@hostname_of_private_instance
o You can now access the private instance via the public instance

Build