Skip to main content
AWS VPC Architecture

Module Overview

Estimated Time: 5-6 hours | Difficulty: Intermediate-Advanced | Prerequisites: Core Concepts
This module covers AWS networking from fundamentals to advanced architectures. You’ll learn to design secure, scalable, and highly available network topologies. What You’ll Learn:
  • 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.
AWS Load Balancer Types Comparison

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

Architecture:
  1. VPC: 10.0.0.0/16 (65,536 IPs)
  2. 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
  3. Components:
    • ALB in public subnets
    • NAT Gateway per AZ (for HA)
    • App servers in private subnets
    • RDS Multi-AZ in DB subnets
  4. Security:
    • alb-sg: 443 from 0.0.0.0/0
    • web-sg: 8080 from alb-sg
    • db-sg: 3306 from web-sg
  5. Routing:
    • Public: 0.0.0.0/0 → IGW
    • Private: 0.0.0.0/0 → NAT Gateway
Security Groups:
  • Operate at instance level
  • Stateful (return traffic auto-allowed)
  • Allow rules only
  • All rules evaluated
  • Primary security layer
NACLs:
  • Operate at subnet level
  • Stateless (must allow return traffic)
  • Allow AND Deny rules
  • Rules evaluated in order
  • Secondary layer for compliance
Best Practice: Use both for defense in depth. Security groups for fine-grained control, NACLs for subnet-level blocking.
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
Use NLB when:
  • TCP/UDP traffic
  • Need ultra-low latency (<100ms)
  • Need static IP/Elastic IP
  • Gaming, IoT, financial apps
  • Need to preserve source IP
Cost Note: NLB is cheaper at high throughput
Systematic approach:
  1. Security Groups: Check inbound/outbound rules
  2. NACLs: Check subnet NACL rules (inbound AND outbound)
  3. Route Tables: Verify route to destination exists
  4. Internet Gateway: For public access, ensure IGW attached
  5. NAT Gateway: For private subnet outbound, check NAT
  6. VPC Flow Logs: Enable to see accepted/rejected traffic
  7. Instance level: Check OS firewall (iptables, Windows Firewall)
Options:
  1. VPC Peering:
    • 1-to-1 connection
    • Non-transitive
    • Good for fewer than 10 VPCs
    • No single point of failure
  2. Transit Gateway:
    • Hub-and-spoke model
    • Transitive routing
    • Scales to 5,000+ VPCs
    • Centralized management
    • ~0.05/GB+0.05/GB + 0.05/attachment/hour
  3. PrivateLink:
    • Expose service to other VPCs
    • One-way access
    • No IP overlap concerns
Recommendation:
  • 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 segmentation
1

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

Key Takeaways:
  1. Always use at least 2 AZs for high availability
  2. Place only load balancers in public subnets
  3. Use security group chaining (reference SGs, not IPs)
  4. Plan CIDR blocks to avoid overlap for future peering
  5. Use NAT Gateway per AZ for HA
  6. Enable VPC Flow Logs for troubleshooting
  7. Use Transit Gateway for 5+ VPCs

Next Module

Security

Master IAM, KMS, encryption, and security best practices