By the end of this article, you will learn:
- How to create a Virtual Private Cloud (VPC)
- How to create subnets in your VPC
- How to associate Route Tables and an Internet Gateway to allow access from the subnet to the public internet
- Where to specify the Virtual Private Cloud to deploy into when creating EC2 instances
Create a Virtual Private Cloud
Log in to AWS, then navigate to VPC in AWS Services.
Virtual Private Clouds, or VPCs for short, are “Regional” resources in AWS, so make sure you are in the right region.
If you don’t see all your VPCs listed out, click on “Your VPCs” in the sidebar.
Hit the “Create VPC” button. Fill in the name tag, IPv4/6 CIDR blocks, and Tenancy. Then, submit and await your success message.
Await your success message, then close. You will now see your VPC show up in “Your VPCs”.
Create a Subnet
After creating a VPC, you can divide your Virtual Private Cloud network into smaller subnetworks. Usually, this division helps with security.
Navigate to “Subnets” on the side panel, or just visit this link (for us-east-1): https://console.aws.amazon.com/vpc/home?region=us-east-1#subnets:sort=SubnetId
You should see your subnets listed in a table. Hit the “Create subnet” button. You should now see a form.
Your VPC’s ID will vary. Clicking on the field will show a dropdown with your VPCs listed with ID and name.
Hit “Create”. Await your success message, then hit Close. Your VPC’s subnet will now be listed.
This VPC subnet has not been configured to access the public internet. For that, you need to hook up an internet gateway. For illustrative purposes, I’ve created a second subnet (e91–jamesfulford01: 192.168.1.0/24) which I will keep private.
Enable auto-assign IP
Select your soon-to-be-public subnet, then click “Actions”. Select “Modify auto-assign IP settings”.
Smash that checkbox.
Click “Save”. You will be returned to the subnet list page.
Create an Internet Gateway
You need one of these in order to grant the Internet access to your subnet. The IPs will be automatically assigned.
Navigate to Internet Gateways, or visit (for us-east-1) https://console.aws.amazon.com/vpc/home?region=us-east-1#igws:sort=internetGatewayId.
Hit the “Create Internet gateway” button. Fill in the form.
Hit “Create”. Await the success message, then hit Close. You will be directed back to the Internet Gateways index page, where you will see your new Internet gateway.
Next, attach your Internet Gateway to your Virtual Private Cloud. Select your IGW and hit “Actions”. Select “Attach to VPC”.
Select your VPC. Clicking on the field will show you your VPCs’ IDs and name tags.
Hit “Attach”. You’ll be redirected back to the IGW index page, and your IGW will have an “attached” state.
At this point, your subnet is still not connected to the internet.
Add and Configure a Routing Table
Navigate to Route Tables, or visit (for us-east-1): https://console.aws.amazon.com/vpc/home?region=us-east-1#RouteTables:sort=routeTableId.
Hit “Create route table”. Fill in the form.
Hit “Create”, then await success message and hit “Close”. You will be returned to the Route Table index page.
Now, let’s configure our Route Table. Select the Route table of interest, then switch to the Routes tab.
Hit the “Edit Routes” button. You will see a list of routes.
Hit “Add route” and fill in the row.
Hit “Save routes”. This new route will not make an impact until the table is associated with a subnet. To associate the routing table with a subnet, select the table and under “Actions”, select “Edit subnet associations”.
In the next menu, select the subnet(s) you wish to associate with the previously selected route table. In my example, I wish to associate this with the 192.168.0.0/24 subnet.
Hit “Save”. You will be redirected back to the Route Tables index page.
You now have a Virtual Private Cloud set up with 2 small subnets (1 private, 1 with public Internet access).
You can leverage your new VPC and subnets when creating EC2 instances by specifying the Network and Subnet selectors during the “Configure Instance” step.
Interested in using EC2 and VS Code as a development environment, instead of your laptop? Check out my walkthrough on using the remote SSH development VS Code extension here: https://email@example.com/aws-vscode-ssh-devenv-73fd540294d1