VPC & Networking in AWS
Designing Secure, Scalable, and Isolated Network Architectures
π What is a Virtual Private Cloud (VPC)?
A Virtual Private Cloud (VPC) is a logically isolated section of AWS where you can launch AWS resources (like EC2, RDS, Lambda) in a custom-defined networkβwith full control over IP addressing, subnets, routing, and security.
Think of it as your own virtual data center in AWS.
Core Components of a VPC
Component | Description |
---|---|
CIDR Block | IP address range for the VPC (e.g., 10.0.0.0/16) |
Subnets | Subdivisions of the VPC (public/private) |
Route Tables | Define where network traffic is directed |
Internet Gateway | Enables outbound internet access |
NAT Gateway | Allows private subnets to access the internet |
Security Groups | Firewall rules at instance level |
Network ACLs | Firewall rules at subnet level (stateless) |
VPC Peering | Connect two VPCs privately |
Default VPC vs Custom VPC
Feature | Default VPC | Custom VPC |
---|---|---|
Automatically created | Yes | No |
Subnets | 1 per AZ | User-defined |
Internet Access | Configured | Needs explicit IGW, route |
Use Case | Testing, quick deployments | Production, isolated setups |
ASCII Diagram β Custom VPC Layout (Typical 2-Tier App)
Plaintext
+----------------------+
| Internet |
+----------+-----------+
|
+---------v----------+
| Internet Gateway |
+---------+----------+
|
+-------------+--------------+
| |
+-------v--------+ +--------v-------+
| Public Subnet 1| | Public Subnet 2|
| (Web Servers) | | (ALB/NAT GW) |
+-------+--------+ +--------+-------+
| |
+-------v--------+ +--------v-------+
| Private Subnet1| | Private Subnet2|
| (App/DB Layer) | | (RDS, EC2) |
+----------------+ +----------------+
How to Create a Custom VPC (Step-by-Step)
β Via AWS Console:
- Go to VPC Dashboard β Create VPC
- Choose VPC Only or VPC + Subnets (Wizard)
- Enter:
- Name:
my-production-vpc
- IPv4 CIDR:
10.0.0.0/16
- Tenancy: Default
- Name:
- Click Create
β Create Subnets:
- Public Subnet:
10.0.1.0/24
- Private Subnet:
10.0.2.0/24
β Add an Internet Gateway:
- Create and attach to the VPC
- Update route table for public subnet β Route to IGW
β Add NAT Gateway (for Private Subnet):
- Deploy in public subnet
- Associate Elastic IP
- Route traffic from private subnet β NAT Gateway
π‘οΈ Security in VPC β SG vs NACL
Feature | Security Group | Network ACL |
---|---|---|
Level | Instance-level (stateful) | Subnet-level (stateless) |
Rules | Allow only | Allow and Deny |
State | Stateful | Stateless |
Use Case | App-level protection | Subnet-wide firewall |
Example Security Group:
Bash
Inbound: TCP 22 (SSH) from MyIP
Inbound: TCP 80 (HTTP) from 0.0.0.0/0
Outbound: ALL
Example NACL Rules:
- Allow TCP 80 from 0.0.0.0/0 (Inbound)
- Deny all other traffic (Explicit)
NAT Gateway vs Internet Gateway
Feature | Internet Gateway | NAT Gateway |
---|---|---|
For Subnet Type | Public Subnet | Private Subnet |
Inbound Access | Yes (public IP) | No |
Outbound Internet | Yes | Yes |
Elastic IP Needed | Optional | Required |
Cost | Free | Paid (by hour & GB) |
Route Tables Explained
A route table controls how traffic is routed from subnets.
Example Routes:
Destination | Target |
---|---|
10.0.0.0/16 | local |
0.0.0.0/0 | igw-xxxxxxxx |
VPC Peering & PrivateLink
β VPC Peering
- Connect two VPCs privately (no internet/GW needed)
- Same or different accounts/regions
- Add route entries in both VPCs
β AWS PrivateLink
- Access services like S3, Kinesis privately over interface VPC endpoints
- No need to route traffic over public internet
Advanced Network Architectures
β VPC with Multiple AZs and Load Balancer:
LESS
[Internet]
|
[Route 53 DNS]
|
[Application Load Balancer]
/ \
[EC2 in Public AZ-A] [EC2 in Public AZ-B]
\ /
[Private Subnet with RDS in Multi-AZ]
β Best for fault tolerance & multi-AZ failover.
β Hybrid Cloud with VPN:
Bash
[On-Prem Firewall]----[AWS VPN Gateway]---[Private Subnet]
Use Site-to-Site VPN or Direct Connect for hybrid models.
Monitoring & Troubleshooting Tools
Tool | Use Case |
---|---|
VPC Flow Logs | Monitor IP traffic per ENI |
CloudWatch | Alarm for NAT data usage |
Reachability Analyzer | Visual tool to trace network path |
AWS Config | Audit changes in VPC config |
Best Practices for VPC Design
- Use CIDR blocks with growth room (e.g.,
/16
) - Split VPC into public/private subnets
- One AZ failure should not affect all resources
- Always use NAT Gateway + Private Subnet for app/database layers
- Use Network ACLs for subnet-wide protection
- Add flow logs for security audits and troubleshooting
- Tag your resources (
Environment
,Owner
,CostCenter
) - Use VPC Endpoints for secure S3/DynamoDB access
- Place RDS/Databases in private subnets
Summary
Concept | Description |
---|---|
VPC | Virtual network in AWS |
Subnets | Public (for ALB), Private (for DB) |
IGW vs NAT GW | Public internet vs secure outbound |
Route Tables | Control traffic directions |
Security Layers | Security Groups + NACLs |
VPC Peering | Cross-VPC private networking |
Monitoring | Flow Logs, CloudWatch, Reachability Analyzer |
π‘ Explore More AWS Tools & Resources
π
Educational AI Tutor
Get instant AWS-related answers and explanations using AI.
π§
Interview Question Generator
Generate AWS interview questions for practice and preparation.
π
AWS Practice Quiz
Test your AWS knowledge with timed quizzes and scoring.
π
AWS Interview Questions
Browse frequently asked AWS interview questions with answers.