Understanding AWS Networking Through City Planning
Imagine you're a city planner designing a new residential neighborhood from scratch. You need to decide where to put houses, which streets should be public vs private, and how to control traffic flow. This is exactly what you're doing when you set up a VPC (Virtual Private Cloud) in AWS - except instead of houses, you're placing servers, databases, and applications.
A VPC is like purchasing a large plot of land where you'll build your entire neighborhood. It's your private space within the larger AWS "city."
Default VPC (pre-built neighborhood):
Custom VPC (design your own):
Subnets are like individual streets within your VPC community:
Layout example:
VPC: 10.0.0.0/16 (Your entire community)
├── Public Subnet: 10.0.1.0/24 (Main Street - visible to internet)
├── Private Subnet: 10.0.10.0/24 (Residential street - internal only)
└── Database Subnet: 10.0.20.0/24 (High-security area)
Public Subnets (Front Yard):
Private Subnets (Backyard):
VPC: 10.0.0.0/16
├── us-west-2a
│ ├── Public: 10.0.1.0/24 (Load balancers)
│ └── Private: 10.0.10.0/24 (App servers)
└── us-west-2b
├── Public: 10.0.2.0/24 (Load balancers)
└── Private: 10.0.11.0/24 (App servers)
Subnet sizing tip: AWS reserves 5 IP addresses in each subnet, so a /24 subnet (256 total) gives you 251 usable addresses.
Security Groups are like having a personal security guard for each resource with a specific guest list.
Three-tier web application:
Internet → Load Balancer (Public-SG) → Web Servers (Web-SG) → App Servers (App-SG) → Database (DB-SG)
Web Server Security Group:
{
"WebServer-SG": {
"Inbound": [
{"Port": 80, "Source": "0.0.0.0/0", "Note": "HTTP from anywhere"},
{"Port": 443, "Source": "0.0.0.0/0", "Note": "HTTPS from anywhere"},
{"Port": 22, "Source": "Office-IP-Range", "Note": "SSH from office only"}
]
}
}
Application Server Security Group:
{
"AppServer-SG": {
"Inbound": [
{"Port": 8080, "Source": "WebServer-SG", "Note": "Only from web servers"},
{"Port": 22, "Source": "Bastion-SG", "Note": "SSH through bastion only"}
]
}
}
Database Security Group:
{
"Database-SG": {
"Inbound": [
{"Port": 3306, "Source": "AppServer-SG", "Note": "MySQL from app servers only"}
]
}
}
Free:
Costs Money:
Strategy 1: Smart NAT Gateway Usage
{
"NATOptimization": {
"Production": {
"Setup": "Multi-AZ NAT Gateways",
"Cost": "$97/month",
"Justification": "High availability required"
},
"Development": {
"Setup": "Single NAT Gateway with scheduling",
"Schedule": "8 AM - 6 PM weekdays only",
"Cost": "$16/month (75% savings)",
"Justification": "Dev work only during business hours"
}
}
}
Strategy 2: VPC Endpoints for AWS Services
{
"S3AccessExample": {
"ViaNATGateway": "$45/month (NAT + data processing + transfer)",
"ViaVPCEndpoint": "$0/month (S3 Gateway endpoint is free)",
"AnnualSavings": "$540/year per heavy S3 user"
}
}
Strategy 3: Same-AZ Placement
{
"CrossAZOptimization": {
"Problem": "Cross-AZ traffic costs $0.01/GB",
"Solution": "Place frequently communicating resources in same AZ",
"Example": {
"BadDesign": "Web server in 2a, Database in 2b → $10/month data transfer",
"GoodDesign": "Both in 2a → $0/month (use read replicas for HA)"
}
}
}
Wrong:
{"Port": 22, "Source": "0.0.0.0/0"} // SSH open to entire internet!
Better options:
{"Port": 22, "Source": "Office-IP-Range"} // Office only
{"Port": 22, "Source": "Bastion-SG"} // Through bastion host
{"Method": "AWS Systems Manager"} // No SSH ports needed
Short-sighted design:
VPC: 10.0.0.0/24 (Only 254 addresses total!)
Growth-friendly design:
VPC: 10.0.0.0/16 (65,534 addresses)
├── Reserved space for future growth
└── Room for multiple environments
Security groups control BOTH inbound and outbound traffic:
Problem:
{
"WebServer-SG": {
"Inbound": [{"Port": 80, "Source": "0.0.0.0/0"}],
"Outbound": [] // Forgot to allow outbound HTTPS!
}
}
Result: Web server can receive requests but can't make API calls or download updates.
# 1. Create VPC
VPC_ID=$(aws ec2 create-vpc --cidr-block 10.0.0.0/16 --query 'Vpc.VpcId' --output text)
# 2. Create Internet Gateway
IGW_ID=$(aws ec2 create-internet-gateway --query 'InternetGateway.InternetGatewayId' --output text)
aws ec2 attach-internet-gateway --vpc-id $VPC_ID --internet-gateway-id $IGW_ID
# 3. Create Public Subnet
PUBLIC_SUBNET=$(aws ec2 create-subnet --vpc-id $VPC_ID --cidr-block 10.0.1.0/24 --query 'Subnet.SubnetId' --output text)
# 4. Create Private Subnet
PRIVATE_SUBNET=$(aws ec2 create-subnet --vpc-id $VPC_ID --cidr-block 10.0.10.0/24 --query 'Subnet.SubnetId' --output text)
# 5. Create Security Groups
WEB_SG=$(aws ec2 create-security-group --group-name WebServer-SG --description "Web servers" --vpc-id $VPC_ID --query 'GroupId' --output text)
# 6. Configure Security Group Rules
aws ec2 authorize-security-group-ingress --group-id $WEB_SG --protocol tcp --port 80 --cidr 0.0.0.0/0
aws ec2 authorize-security-group-ingress --group-id $WEB_SG --protocol tcp --port 443 --cidr 0.0.0.0/0
"My instance can't reach the internet"
Check:
"Database connection timeouts"
Check:
"High data transfer costs"
Solutions:
Internet → Bastion (Public Subnet) → Private Servers (Private Subnet)
Instead of opening SSH to internet, use secure jump host:
{
"Bastion-SG": {
"Inbound": [{"Port": 22, "Source": "Office-IP"}],
"Outbound": [{"Port": 22, "Target": "PrivateServers-SG"}]
}
}
{
"VPCPeering": {
"Production": "10.0.0.0/16",
"Staging": "10.1.0.0/16",
"Use": "Share databases or monitoring between environments",
"Cost": "$0.01/GB for data transfer"
}
}
Understanding VPC networking is like mastering neighborhood design - it balances security, efficiency, and cost:
The investment in proper VPC design pays dividends in reduced costs, improved security, and better operational efficiency.
Need help optimizing your VPC costs while maintaining security? Huskar provides intelligent resource scheduling that works within your VPC security boundaries. Our network-aware optimization ensures cost-saving automation never compromises your carefully designed security architecture. Try our free tier to see how smart scheduling reduces AWS networking costs.
AWS, VPC, Networking, Subnets, Security Groups, Cloud Architecture, Cost Optimization, ELI5