0
0
AWScloud~10 mins

Public vs private subnets in AWS - Visual Side-by-Side Comparison

Choose your learning style9 modes available
Process Flow - Public vs private subnets
Start: Create VPC
Create Subnets
Public Subnet
Attach Internet Gateway
Public Resources
Direct Internet Access
This flow shows creating a VPC with two subnets: one public with internet access, one private without direct internet access.
Execution Sample
AWS
Create VPC
Create Public Subnet with route to Internet Gateway
Create Private Subnet without direct internet route
Launch EC2 in Public Subnet
Launch EC2 in Private Subnet
This setup creates a network with public and private subnets and launches servers in each to show their internet access differences.
Process Table
StepActionSubnet TypeRoute TableInternet AccessResult
1Create VPCN/AN/AN/AVPC created
2Create Public SubnetPublicRoute to Internet GatewayYesSubnet ready for public resources
3Create Private SubnetPrivateNo direct internet routeNoSubnet isolated from internet
4Launch EC2 in Public SubnetPublicRoute to Internet GatewayYesEC2 can access internet directly
5Launch EC2 in Private SubnetPrivateNo direct internet routeNoEC2 cannot access internet directly
6Add NAT Gateway in Public SubnetPublicRoute to Internet GatewayYesNAT Gateway ready
7Update Private Subnet Route TablePrivateRoute to NAT GatewayIndirectPrivate EC2 can access internet via NAT
8Test Private EC2 Internet AccessPrivateRoute to NAT GatewayIndirectPrivate EC2 accesses internet through NAT
9EndN/AN/AN/ASetup complete
💡 Setup ends after configuring NAT Gateway and verifying private subnet internet access via NAT.
Status Tracker
VariableStartAfter Step 2After Step 3After Step 6After Step 7Final
Public Subnet Route TableNoneRoute to Internet GatewayRoute to Internet GatewayRoute to Internet GatewayRoute to Internet GatewayRoute to Internet Gateway
Private Subnet Route TableNoneNoneNo direct internet routeNo direct internet routeRoute to NAT GatewayRoute to NAT Gateway
Public EC2 Internet AccessN/AN/AN/AN/AN/AYes (direct)
Private EC2 Internet AccessN/AN/ANoNoYes (via NAT)Yes (via NAT)
Key Moments - 3 Insights
Why can't EC2 in the private subnet access the internet directly after creation?
Because the private subnet's route table does not have a route to the Internet Gateway, as shown in execution_table step 5.
How does the private subnet gain internet access indirectly?
By adding a NAT Gateway in the public subnet and updating the private subnet's route table to route internet traffic through the NAT, as shown in steps 6 and 7.
Why is the public subnet able to access the internet directly?
Because its route table includes a route to the Internet Gateway, allowing direct internet access, as shown in step 2 and 4.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 5. What is the internet access status of the EC2 instance in the private subnet?
ANo direct internet access
BDirect internet access
CAccess via NAT Gateway
DInternet access blocked by security group
💡 Hint
Refer to the 'Internet Access' column in execution_table row 5.
At which step does the private subnet gain indirect internet access?
AStep 4
BStep 7
CStep 2
DStep 3
💡 Hint
Check the 'Internet Access' and 'Result' columns in execution_table rows 6 and 7.
If the NAT Gateway was not added, how would the private subnet's internet access change in the variable_tracker?
AIt would become 'Yes (via NAT)' after step 7
BIt would become 'Yes (direct)' after step 7
CIt would remain 'No' for all steps
DIt would be 'No' initially and 'Yes (direct)' after step 6
💡 Hint
Look at the 'Private EC2 Internet Access' row in variable_tracker and consider the role of NAT Gateway.
Concept Snapshot
Public vs Private Subnets in AWS:
- Public subnet has route to Internet Gateway (IGW) allowing direct internet access.
- Private subnet lacks direct IGW route, isolating it from internet.
- NAT Gateway in public subnet enables private subnet internet access indirectly.
- Route tables control traffic flow for each subnet.
- Use public subnets for internet-facing resources, private for internal-only.
Full Transcript
This lesson shows how to set up public and private subnets in AWS. First, a VPC is created. Then, two subnets are made: one public with a route to the Internet Gateway, and one private without. EC2 instances launched in the public subnet can access the internet directly. Those in the private subnet cannot. To allow private subnet instances internet access, a NAT Gateway is added in the public subnet. The private subnet's route table is updated to send internet traffic through the NAT Gateway. This setup keeps private resources secure while allowing them to reach the internet when needed.