Creating a VPC with 2 Public and Private Subnet in AWS

Akrur Neupane
3 min readJun 14, 2023

--

We will set up a new virtual private cloud (VPC). This new VPC will have four subnets (two public subnets and two private subnets) and two route tables (one public route table and one private route table). Then, we will launch an EC2 instance inside the new VPC.

Creating the VPC

  1. In the Services search box, enter VPC and open the VPC console by choosing VPC from the list.
  2. In the navigation pane, under Virtual private cloud, choose Your VPCs.
  3. Choose Create VPC.
  4. Configure these settings:
  • Name tag: app-vpc
  • IPv4 CIDR block: 10.1.0.0/16

5. Choose Create VPC.

6. In the navigation pane, under Virtual private cloud, choose Internet gateways

7. Choose Create internet gateway.

8. For Name tag, paste app-igw and choose Create internet gateway.

9. In the details page for the internet gateway, choose Actions and then choose Attach to VPC.

10. For Available VPCs, choose app-vpc and then choose Attach internet gateway.

Creating subnets

From the navigation pane, choose Subnets.

Choose Create subnet.

For the first public subnet, configure these settings:

  • VPC ID: app-vpc
  • Subnet name:Public Subnet 1
  • Availability Zone: Choose the first Availability Zone
  • Example: If you are in US West (Oregon), you would choose us-west-2a
  • IPv4 CIDR block: 10.1.1.0/24

Choose Add new subnet.

For the second public subnet, configure these settings:

  • Subnet name: Public Subnet 2
  • Availability Zone: Choose the second Availability Zone
  • Example: If you are in US West (Oregon), you would choose us-west-2b
  • IPv4 CIDR block: 10.1.2.0/24

Choose Add new subnet and for the first private subnet, configure these settings:

  • Subnet name: Private Subnet 1
  • Availability Zone: Choose the first Availability Zone
  • Example: If you are in US West (Oregon), you would choose us-west-2a
  • IPv4 CIDR block: 10.1.3.0/24.

Choose Add new subnet and for the second private subnet, configure the following:

  • Subnet name: Private Subnet 2
  • Availability Zone: Choose the second Availability Zone
  • Example: If you are in US West (Oregon), you would choose us-west-2b
  • IPv4 CIDR block: 10.1.4.0/24

Finally, choose Create subnet.

After the subnets are created, select the check box for Public Subnet 1.

Choose Actions and then choose Edit subnet settings.

For Auto-assign IP settings, select Enable auto-assign public IPv4 address and then choose Save.

Clear the check box for Public Subnet 1 and select the check box for Public Subnet 2.

Again, choose Actions and then Edit subnet settings.

For Auto-assign IP settings, select Enable auto-assign public IPv4 address and save the settings.

Creating route tables

In the navigation pane, choose Route Tables.

Choose Create route table.

For the route table, configure these settings:

  • Name: app-routetable-public
  • VPC: app-vpc

Choose Create route table.

If needed, open the route table details pane by choosing app-routetable-public from the list.

Choose the Routes tab and choose Edit routes.

Choose Add route and configure these settings:

  • Destination: 0.0.0.0/0
  • Target: Internet Gateway, then choose app-igw (which you set up in the VPC task)

Choose Save changes.

Choose the Subnet associations tab.

Scroll to Subnets without explicit associations and choose Edit subnet associations.

Select the two public subnets that you created (Public Subnet 1 and Public Subnet 2) and choose Save associations.

In the navigation pane, choose Route Tables.

Choose Create route table and configure these settings:

  • Name: app-routetable-private
  • VPC: app-vpc

Choose Create route table.

If needed, open the details pane for app-routetable-private by choosing it from the list.

Choose the Subnet associations tab.

Scroll to Subnets without explicit associations and choose Edit subnet associations.

Select the two private subnets (Private Subnet 1 and Private Subnet 2) and choose Save associations.

Now we have created a VPC on AWS, we can now launch EC2 on our own VPC on AWS

--

--