Use when working with AWS networking - designing VPCs, subnets, routing, security groups, NACLs, internet/NAT gateways, VPC peering, Transit Gateway, VPN, Direct Connect, VPC endpoints, flow logs, or any AWS network architecture and troubleshooting decisions
Comprehensive AWS VPC and networking guidance covering architecture design, security, connectivity, and production patterns. Based on the official AWS VPC documentation and best practices.
Security Groups are stateful, instance-level firewalls.
Key behaviors:
Applied to ENIs (Elastic Network Interfaces), not subnets
Stateful: Return traffic is automatically allowed
Only allow rules — no deny rules
All outbound traffic allowed by default (on new SGs)
Multiple SGs can be applied to one instance
SG rules can reference other SG IDs (not just CIDRs)
Best practices:
✅ DO:
- Use least-privilege rules (specific ports/sources)
- Reference SG IDs for inter-tier traffic (e.g., allow ALB SG → App SG)
- Name SGs descriptively (e.g., "web-tier-sg", "db-sg")
- Regularly audit unused rules
❌ DON'T:
- Open 0.0.0.0/0 to SSH/RDP (use SSM Session Manager instead)
- Use a single catch-all SG for all resources
- Open all ports between tiers — only allow what's needed
Common pattern — 3-tier web app:
ALB SG: Inbound: 443 from 0.0.0.0/0
App SG: Inbound: 8080 from ALB SG
DB SG: Inbound: 5432 from App SG
Security: Network ACLs (NACLs)
NACLs are stateless, subnet-level firewalls.
Key behaviors:
Applied at the subnet boundary
Stateless: Must explicitly allow both inbound AND outbound (including ephemeral ports)
Supports both allow and deny rules
Rules evaluated in order (lowest number first) — first match wins
Default NACL allows all traffic; custom NACLs deny all by default
Ephemeral port ranges (must allow for return traffic):
Client OS
Ephemeral Port Range
Linux
32768–60999
Windows
49152–65535
AWS NAT Gateway
1024–65535
NACLs vs Security Groups — when to use which:
Use Case
Tool
Primary access control
Security Groups
Block specific IPs/CIDRs
NACLs (use deny rules)
Defense-in-depth second layer
NACLs
Subnet-wide policy enforcement
NACLs
NACLs cannot block:
Route 53 Resolver DNS (VPC+2 address) — use Route 53 Resolver DNS Firewall instead
EC2 Instance Metadata Service (IMDS)
DHCP, Time Sync Service, Windows license activation
VPC-to-VPC Connectivity
VPC Peering
Direct, private connection between two VPCs
Can peer across Regions and accounts
Not transitive — if A↔B and B↔C, A cannot reach C through B
No bandwidth bottleneck or single point of failure
Both VPCs must have non-overlapping CIDR blocks
Requires route table entries + SG rules on both sides
When to use: Small number of VPC-to-VPC connections, simple topology.
Transit Gateway (TGW)
Regional hub-and-spoke router
Connects: VPCs, VPN connections, Direct Connect gateways, other TGWs (peering)
Transitive routing — all attached VPCs can communicate (by default)
Supports thousands of attachments
Supports route tables for traffic segmentation
Costs: hourly attachment fee + per-GB data transfer
When to use: Many VPCs, hybrid connectivity, complex routing requirements.
Use for: keeping service traffic off the internet, compliance requirements
When to use which:
S3 or DynamoDB from private subnet → Gateway Endpoint (free)
Any other AWS service from private subnet → Interface Endpoint
Cross-account private service exposure → PrivateLink
IP Addressing
IPv4
Private (RFC 1918): 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 — no charge
Public IPv4: Charged ($0.005/hr per IP, ~$3.65/mo) — minimize public IPs
Elastic IP (EIP): Static public IPv4; charged when not associated with a running instance
BYOIP: Bring your own public IP ranges to AWS
IPv6
All IPv6 addresses are publicly routable (no private IPv6 equivalent)
Use Egress-Only IGW to control outbound-only access
No NAT for IPv6
Free to use (no charge for IPv6 addresses)
Dual-stack (IPv4 + IPv6) supported on VPCs and subnets
Monitoring & Observability
VPC Flow Logs
Captures metadata about IP traffic (not packet contents) to/from ENIs, subnets, or VPCs
Destinations: CloudWatch Logs, S3, Kinesis Data Firehose
Versions: v2 (default) through v7 with increasingly rich fields
Common use cases: Security analysis, troubleshooting connectivity, compliance auditing
Cost: CloudWatch ingestion + storage, S3 storage
Flow log record fields (v2):
version account-id interface-id srcaddr dstaddr srcport dstport protocol packets bytes start end action log-status
Reading flow logs for troubleshooting:
ACCEPT = traffic was allowed by SG + NACL
REJECT = traffic was blocked by SG or NACL
No record = traffic never reached the interface (check routing)
Traffic Mirroring
Copies actual packet data from ENIs to inspection appliances
Use for: IDS/IPS, deep packet inspection, forensics
Source and destination must be in same VPC (or peered/TGW connected)
Additional cost per mirrored session
Network Access Analyzer
Identifies unintended network access paths to resources
Finds overly permissive configurations before they're exploited
AWS Network Firewall
Managed stateful firewall deployed inside your VPC