Cost Optimization Patterns
Compute:
- On-Demand → Reserved/Savings Plans for predictable workloads (up to 72% discount).
- Spot for fault-tolerant, stateless, batch jobs (up to 90% off).
- Lambda for infrequent/short tasks vs. always-on EC2.
- ASG with mixed instance types (On-Demand + Spot fleet).
- Right-size instances using Compute Optimizer.
Storage:
- S3 lifecycle policies to move data to cheaper tiers automatically.
- S3 Intelligent-Tiering for unknown access patterns.
- EBS: choose the right volume type (sc1 for cold, st1 for sequential).
- Delete unused EBS snapshots and EBS volumes.
Networking costs (simplified):
- Traffic within same AZ: free (use private IP).
- Cross-AZ traffic with private IP: $0.01/GB.
- Cross-AZ traffic with public IP: $0.02/GB.
- Cross-region: $0.02/GB.
- S3 to CloudFront: free. CloudFront to internet: ~$0.085/GB (cheaper than S3 direct to internet).
- S3 via NAT Gateway: expensive (NAT data processing charges). Use VPC Gateway Endpoint for S3 instead (free, saves NAT costs).
- Keep traffic within AWS. Prefer private IPs. Use same AZ for high-throughput (sacrifices HA).
Database:
- Use RDS Reserved Instances for known workloads.
- Aurora Serverless for intermittent workloads.
- ElastiCache to reduce DB read load.
- Read Replicas for read scaling (cheaper than larger primary).
- DynamoDB On-Demand for unpredictable. Provisioned + Auto-Scaling for predictable.
Load Balancers:
- ALB (Layer 7) — HTTP/HTTPS, path routing.
- NLB (Layer 4) — TCP/UDP, extreme performance, static IP.
- GWLB — 3rd-party security appliances.
