Any EC2 running on a private subnet can be accessed from another EC2 instance from within VPC network or over a VPN network. The instances running are not accessible via the public internet. Each VPC has a default internet gateway associated with it. A new subnet is always created as a public subnet. The public subnet can be changed to a private subnet by assigning its route table to a private route table:
- The first step is to create a private route table:
- From the VPC dashboard, navigate to Route Tables and click on the Create Route Table button:
![](http://images-20200215.ebookreading.net/11/2/2/9781787281066/9781787281066__learning-aws-__9781787281066__assets__e3ad4299-a3a1-4c1f-8194-b03196326a73.png)
-
- In the Create Route Table popup, assign the name of the route table in the Name tag. Click on the Yes, Create button:
![](http://images-20200215.ebookreading.net/11/2/2/9781787281066/9781787281066__learning-aws-__9781787281066__assets__53197b97-1502-4ba0-bb88-613cdff3703c.png)
-
- You should see the following screen:
![](http://images-20200215.ebookreading.net/11/2/2/9781787281066/9781787281066__learning-aws-__9781787281066__assets__d0b49225-11d7-459b-8890-de4b5af69458.png)
- The next step is to create a subnet:
- From the VPC dashboard, navigate to Subnets and then click on Create Subnets:
![](http://images-20200215.ebookreading.net/11/2/2/9781787281066/9781787281066__learning-aws-__9781787281066__assets__c4b37de7-7212-4260-87ad-a000ebc24539.png)
-
- Name tag: Specify a name for the subnet. This name will be reflected in the VPC dashboard.
- VPC: Choose the VPC in which this subnet will be created. Select the option containing 172.31.0.0/16 from the dropdown if you have more than one VPC.
- Availability Zone: The availability zone in which this subnet will be created. From the dropdown, select us-west-2a; this is one of the two private subnets. The other one will created in the us-west-2c Availability Zone as per the deployment architecture.
- CIDR block: Classless Inter-Domain Routing (CIDR) defines a range of IP addresses to be allocated to the hosts in the subnet. In this case, 172.31.80.0/20 defines the IP address range from 172.31.80.0 to 172.31.95.255 (a total of 4,096 hosts):
![](http://images-20200215.ebookreading.net/11/2/2/9781787281066/9781787281066__learning-aws-__9781787281066__assets__81abbaa2-b034-4874-b649-bc96fd35a116.png)
- You should see the following screen:
![](http://images-20200215.ebookreading.net/11/2/2/9781787281066/9781787281066__learning-aws-__9781787281066__assets__a7910dba-a820-4bf7-86db-a376fcbba4e8.png)
- The last step is to associate the private route table created in step 1 with the subnet created in step 2:
- From the VPC dashboard, navigate to Subnets and click on the subnet created in step 2.
- Navigate to Route Table tab in the bottom pane and click on Edit:
![](http://images-20200215.ebookreading.net/11/2/2/9781787281066/9781787281066__learning-aws-__9781787281066__assets__2fd418d6-2036-472c-8066-34be936122d3.png)
-
- From the Change To dropdown, select the route created in step 1:
![](http://images-20200215.ebookreading.net/11/2/2/9781787281066/9781787281066__learning-aws-__9781787281066__assets__c8a57fb5-15e9-4d26-b75f-08e2396cbca8.png)
Similarly create another subnet, Private Subnet, with CIDR block 172.31.96.0/20 in the Availability Zone us-west-2c; assign the private route table to it (created in step 1):
![](http://images-20200215.ebookreading.net/11/2/2/9781787281066/9781787281066__learning-aws-__9781787281066__assets__1f32f72d-ed1c-4ab9-9abd-22eb8c574476.png)