Create NAT Gateway
Create a NAT Gateway
ℹ️ NAT Gateway Overview
A NAT Gateway (Network Address Translation Gateway) is a managed AWS service that lets instances in a private subnet:
- Connect out to the internet to download updates and packages
- Access AWS services
- Block inbound connections initiated from the internet
🏗️ NAT Gateway Architecture:
EC2 Private → Private Subnet → NAT Gateway → Internet Gateway → Internet
↓
(Elastic IP)
💰 NAT Gateway Cost:
- Hourly charge:
$0.045/hour ($32/month)
- Data processing charge: ~$0.045/GB
- Elastic IP: free while in use, $0.005/hour when unused
💡 Note for This Workshop:
- We’ll create a single NAT Gateway (simple and cost-effective)
- In production, you should have a NAT Gateway in every AZ for high availability
Create an Elastic IP Address
-
Access the EC2 Dashboard
- Select Elastic IPs from the left menu (under Network & Security)
- Click Allocate Elastic IP address
💡 What is an Elastic IP?: A static IPv4 address designed for cloud computing. A NAT Gateway needs an Elastic IP to have a fixed public address.

-
Configure the Elastic IP
- Network Border Group: Keep the default (us-west-1)
- Public IPv4 address pool: Select Amazon’s pool of IPv4 addresses
- Tags (optional): You can add a Name tag = “NAT-Gateway-EIP”
- Click Allocate

-
Confirm the Elastic IP was created
- Note the Allocated IPv4 address
- Current status: Not associated (not yet attached to a resource)
⚠️ Note: An unused Elastic IP is charged $0.005/hour. We’ll attach it to the NAT Gateway right away.

Deploy the NAT Gateway
-
Access the VPC Dashboard
- Select NAT Gateways from the left menu
- Click Create NAT gateway

-
Configure the NAT Gateway
- Name: Enter
NAT gateway
- Subnet: Select Public subnet 2 (or any public subnet)
- Connectivity type: Select Public
- Elastic IP allocation ID: Select the Elastic IP you just created
💡 Why place the NAT Gateway in a public subnet?
- The NAT Gateway needs an Internet Gateway to reach the internet
- Only a public subnet has a route to the Internet Gateway
- The NAT Gateway will use the Elastic IP as its public address

-
Review the configuration and click Create NAT gateway

-
Confirm the NAT Gateway was created
- Initial status: Pending
- After 1-2 minutes, the status changes to Available
⏱️ Wait time: The NAT Gateway takes about 1-2 minutes to initialize. You can continue with the next steps while you wait.

💡 Why do we need a separate route table?
- A private subnet needs different routing than a public subnet
- Traffic from the private subnet must go through the NAT Gateway (not the Internet Gateway)
- Separating the routing improves security and makes management easier
-
In the VPC Dashboard
- Select Route Tables from the left menu
- Click Create route table

-
Set up the route table
- Name: Enter
Route table - Private
- VPC: Select the ASG VPC
- Click Create route table

-
Confirm the route table was created
- Note the Route table ID
- Status: Active
Associate Subnets with the Route Table
-
In the route table you just created
- Select the Subnet associations tab
- Click Edit subnet associations
💡 Subnet Associations: Determine which subnets use this route table to route their traffic.

-
Associate the private subnets
- Select both private subnets:
- Private subnet 1
- Private subnet 2
- Click Save associations
ℹ️ Note: Select only the private subnets. Public subnets already have their own route table with a route to the Internet Gateway.

Add a Route to the NAT Gateway
-
Configure routes
- Select the Routes tab
- Click Edit routes

-
Add a route for internet access
- Click Add route
- Destination: Enter
0.0.0.0/0 (all traffic to the internet)
- Target: Select NAT Gateway, then choose the NAT Gateway you just created
- Click Save changes
💡 Route explanation:
- 0.0.0.0/0: Represents all IP addresses (the internet)
- Target = NAT Gateway: All outbound internet traffic goes through the NAT Gateway
- The NAT Gateway translates the private IP to the Elastic IP before the traffic reaches the internet

-
Confirm the route table configuration
- Check that the route table has 2 routes:
- Local route: Allows communication within the VPC
- 0.0.0.0/0 → NAT Gateway: Allows internet access
✅ Complete route table:
Destination Target
10.10.0.0/16 local (VPC internal traffic)
0.0.0.0/0 nat-xxxxx (Internet traffic)

Check the Internet Connection
-
Return to your SSH session on EC2 Private
- If the session was closed, SSH back in from EC2 Public:
ssh -i aws-keypair.pem ec2-user@<EC2-Private-IP>
-
Run a ping test from the EC2 Private instance
- Test the connection to Amazon:
✅ Expected result: You should receive 5 successful ping responses, confirming EC2 Private can now reach the internet through the NAT Gateway.

-
Additional tests (optional):
# Test DNS resolution
nslookup google.com
# Test HTTP connection
curl -I https://aws.amazon.com
# Update system packages (requires internet)
sudo yum update -y
🏗️ Complete Architecture:
Internet
↕
Internet Gateway (IGW)
↕
Public Subnet 2
↕
NAT Gateway (with Elastic IP)
↕
Private Route Table (0.0.0.0/0 → NAT)
↕
Private Subnet 1 & 2
↕
EC2 Private Instance
🔒 Security Achieved:
- ✅ EC2 Private can connect out to the internet (outbound)
- ✅ The internet CANNOT connect into EC2 Private (inbound blocked)
- ✅ EC2 Private has no public IP (anonymous on the internet)
- ✅ All outbound traffic goes through the NAT Gateway using the Elastic IP
💰 Cost Notes:
- NAT Gateway:
$0.045/hour ($32/month)
- Data processing: ~$0.045/GB
- Elastic IP: free while in use by the NAT Gateway
- Estimated total: ~$35-50/month depending on data transfer volume
⚠️ Important: Remember to delete the NAT Gateway when you’re not using it, to avoid unnecessary charges. We’ll do the cleanup at the end of the workshop.
💡 Best Practices for Production:
- High Availability: Create a NAT Gateway in every AZ
- Monitoring: Track metrics such as BytesOutToDestination and BytesInFromSource
- Cost Optimization: Consider VPC Endpoints for AWS services to reduce data transfer through the NAT Gateway
- Backup Route: Have a contingency plan in case the NAT Gateway has an issue
✅ Done: You’ve successfully created a NAT Gateway and configured routing for the private subnets. The EC2 Private instance can now access the internet securely!