Module Overview
Estimated Time: 5-6 hours | Difficulty: Intermediate-Advanced | Prerequisites: Core Concepts
- VPC design and CIDR planning
- Public and private subnet architectures
- Security groups and NACLs for defense in depth
- Load balancers (ALB, NLB) and routing
- VPC connectivity (Peering, Transit Gateway, VPN)
- Route 53 DNS and CloudFront CDN
- Network troubleshooting techniques
VPC (Virtual Private Cloud)
A VPC is your isolated network in AWS. Every resource you launch runs inside a VPC. Think of a VPC as your own private office building inside a massive shared complex (the AWS data center). You control who enters, which floors connect to each other, and which rooms have windows to the outside world (the internet). Without a VPC, your resources would be sitting in a public parking lot.VPC Architecture Deep Dive
CIDR Planning Guide
VPC with Terraform
Subnets
Subnets divide your VPC into smaller networks. Each subnet exists in a single AZ.Public vs Private Subnets
Gateways
Internet Gateway (IGW)
Allows resources with public IPs to access the internet.NAT Gateway
Allows private subnet resources to access the internet (outbound only).NAT Gateway costs: ~$0.045/hour + data processing charges. Consider NAT instances for dev environments to save costs.
Security Groups Deep Dive
Virtual firewalls for EC2 instances. Stateful - return traffic is automatically allowed. Think of a security group as a bouncer at a club: if you are on the guest list (inbound rule), you get in, and you can leave freely (return traffic). A NACL, by contrast, is like airport security — it checks you on the way in AND on the way out, independently.Security Group Architecture
Security Group with Terraform
Security Groups vs NACLs
Load Balancing
Distribute traffic across multiple targets.Load Balancer Types
Application Load Balancer (ALB)
ALB Features
- Path-based routing:
/api/*→ API servers - Host-based routing:
api.example.com→ API,www.example.com→ Web - SSL termination: HTTPS offloading
- Health checks: Automatic target monitoring
- Sticky sessions: Cookie-based affinity
Route 53
AWS DNS service with health checking and traffic routing.Routing Policies
CloudFront (CDN)
Content Delivery Network for low-latency content delivery.VPC Peering & Transit Gateway
Connect VPCs together.VPC Peering
Transit Gateway
🎯 Interview Questions
Q1: How would you design a VPC for a 3-tier web application?
Q1: How would you design a VPC for a 3-tier web application?
Architecture:
- VPC: 10.0.0.0/16 (65,536 IPs)
-
Subnets (across 3 AZs):
- Public: 10.0.1.0/24, 10.0.2.0/24, 10.0.3.0/24
- Private (App): 10.0.10.0/24, 10.0.11.0/24, 10.0.12.0/24
- Private (DB): 10.0.20.0/24, 10.0.21.0/24, 10.0.22.0/24
-
Components:
- ALB in public subnets
- NAT Gateway per AZ (for HA)
- App servers in private subnets
- RDS Multi-AZ in DB subnets
-
Security:
- alb-sg: 443 from 0.0.0.0/0
- web-sg: 8080 from alb-sg
- db-sg: 3306 from web-sg
-
Routing:
- Public: 0.0.0.0/0 → IGW
- Private: 0.0.0.0/0 → NAT Gateway
Q2: What's the difference between Security Groups and NACLs?
Q2: What's the difference between Security Groups and NACLs?
Security Groups:
- Operate at instance level
- Stateful (return traffic auto-allowed)
- Allow rules only
- All rules evaluated
- Primary security layer
- Operate at subnet level
- Stateless (must allow return traffic)
- Allow AND Deny rules
- Rules evaluated in order
- Secondary layer for compliance
Q3: When would you use ALB vs NLB?
Q3: When would you use ALB vs NLB?
Use ALB when:
- HTTP/HTTPS traffic
- Need path-based routing (/api, /static)
- Need host-based routing (api.example.com)
- WebSocket support
- Container-based apps with dynamic ports
- TCP/UDP traffic
- Need ultra-low latency (<100ms)
- Need static IP/Elastic IP
- Gaming, IoT, financial apps
- Need to preserve source IP
Q4: How do you troubleshoot EC2 connectivity issues?
Q4: How do you troubleshoot EC2 connectivity issues?
Systematic approach:
-
Security Groups: Check inbound/outbound rules
- NACLs: Check subnet NACL rules (inbound AND outbound)
-
Route Tables: Verify route to destination exists
- Internet Gateway: For public access, ensure IGW attached
- NAT Gateway: For private subnet outbound, check NAT
- VPC Flow Logs: Enable to see accepted/rejected traffic
- Instance level: Check OS firewall (iptables, Windows Firewall)
Q5: How do you connect multiple VPCs?
Q5: How do you connect multiple VPCs?
Options:
-
VPC Peering:
- 1-to-1 connection
- Non-transitive
- Good for fewer than 10 VPCs
- No single point of failure
-
Transit Gateway:
- Hub-and-spoke model
- Transitive routing
- Scales to 5,000+ VPCs
- Centralized management
- ~0.05/attachment/hour
-
PrivateLink:
- Expose service to other VPCs
- One-way access
- No IP overlap concerns
- Fewer than 5 VPCs: VPC Peering
- 5+ VPCs: Transit Gateway
🧪 Hands-On Lab: Build a Secure 3-Tier VPC
Objective: Create a production-ready VPC with proper network segmentation1
Create VPC with CIDR 10.0.0.0/16
Enable DNS hostnames and DNS support
2
Create Subnets
3 public (10.0.1-3.0/24), 3 private app (10.0.10-12.0/24), 3 private DB (10.0.20-22.0/24)
3
Create Internet Gateway
Attach to VPC, create public route table with 0.0.0.0/0 → IGW
4
Create NAT Gateways
One per AZ in public subnets, create private route tables
5
Create Security Groups
alb-sg, web-sg, db-sg with proper chaining
6
Deploy ALB + EC2 + RDS
Test connectivity between tiers
7
Enable VPC Flow Logs
Send to CloudWatch Logs for network monitoring
Networking Best Practices Summary
Next Module
Security
Master IAM, KMS, encryption, and security best practices