Cost Optimization & Architecture
AWS Well-Architected framework, cost control strategies, and the architecture patterns that power real production systems
Skills taught: aws.cost-optimization, aws.well-architected, aws.reserved-instances, aws.spot, aws.architecture-patterns, aws.budgets
The AWS Well-Architected Framework
AWS has documented the principles behind every well-built system on their platform in the Well-Architected Framework — six pillars that every production system should be evaluated against. These aren't aspirational guidelines; they're the difference between an architecture that handles incidents gracefully and one that causes them.
1. OPERATIONAL EXCELLENCE
- Infrastructure as Code (CloudFormation/CDK)
- Deploy frequently in small increments
- Automate runbooks — no manual steps in incident response
- Learn from every incident
2. SECURITY
- Implement a strong identity foundation (IAM least privilege)
- Enable traceability (CloudTrail, CloudWatch Logs)
- Automate security best practices
- Protect data in transit (TLS) and at rest (encryption)
3. RELIABILITY
- Design for failure: assume components will fail
- Multi-AZ deployments for stateful resources
- Automatic recovery: health checks + auto-scaling
- Test recovery procedures (game days, chaos engineering)
4. PERFORMANCE EFFICIENCY
- Right-size resources (don't over-provision)
- Use managed services (RDS > self-managed Postgres)
- Experiment: test new instance types, compare costs
- Use CDN for static assets (CloudFront)
5. COST OPTIMIZATION
- Adopt a consumption model (pay for what you use)
- Use Spot for interruptible workloads
- Reserved/Savings Plans for baseline steady-state
- Delete unused resources (biggest hidden cost)
6. SUSTAINABILITY
- Use managed services (more efficient than self-managed)
- Right-size resources to minimize waste
- Use graviton instances (more efficient per compute unit)
Cost optimization — concrete strategies
IMMEDIATE WINS (do these first):
1. Delete unattached EBS volumes
aws ec2 describe-volumes --filters Name=status,Values=available
2. Delete unused Elastic IPs
aws ec2 describe-addresses (costs $0.005/hour if not attached)
3. Delete old EBS snapshots, unused AMIs
4. Stop non-production instances outside business hours
(Lambda to stop EC2 at 6pm, start at 8am = 65% savings)
5. Set S3 lifecycle rules for old data
RESERVED INSTANCES / SAVINGS PLANS:
On-demand: $0.042/hour for t3.medium
1-year RI: $0.026/hour for t3.medium (38% saving)
3-year RI: $0.016/hour for t3.medium (62% saving)
Rule: if it runs 24/7 for > 1 year, buy Reserved Instances
SPOT INSTANCES:
Up to 90% cheaper than on-demand
Can be interrupted with 2-minute notice
Use for: batch jobs, CI/CD runners, ML training, rendering
Don't use for: stateful databases, customer-facing APIs (without graceful handling)
GRAVITON INSTANCES:
t4g vs t3: ~20% cheaper, same performance
m7g vs m6i: ~15% cheaper, ~20% better performance
Requires: Linux OS, compiled-for-ARM binaries
Docker images: add 'linux/arm64' to your multi-platform build
RIGHT-SIZING:
Use CloudWatch metrics: if CPU < 20% average, downsize
AWS Compute Optimizer provides recommendations automatically
Check weekly: 'are we paying for capacity we're not using?'
Setting up billing alerts
# Create a monthly budget with email alert at 80% and 100%
aws budgets create-budget \
--account-id $(aws sts get-caller-identity --query Account --output text) \
--budget '{
"BudgetName": "Monthly-Budget",
"BudgetLimit": {"Amount": "50", "Unit": "USD"},
"TimeUnit": "MONTHLY",
"BudgetType": "COST"
}' \
--notifications-with-subscribers '[{
"Notification": {
"NotificationType": "ACTUAL",
"ComparisonOperator": "GREATER_THAN",
"Threshold": 80,
"ThresholdType": "PERCENTAGE"
},
"Subscribers": [{
"SubscriptionType": "EMAIL",
"Address": "alerts@mycompany.com"
}]
}]'
# Also enable: Billing → Preferences → Receive Billing Alerts
# Then create CloudWatch alarm on 'EstimatedCharges' metric
aws cloudwatch put-metric-alarm \
--alarm-name 'Monthly-Bill-Over-50' \
--namespace AWS/Billing \
--metric-name EstimatedCharges \
--dimensions Name=Currency,Value=USD \
--statistic Maximum \
--period 86400 \
--threshold 50 \
--comparison-operator GreaterThanThreshold \
--evaluation-periods 1 \
--region us-east-1 # billing metrics are always in us-east-1
Reference architecture — production web app
Internet
│
▼
Route53 (DNS + health checks)
│
▼
CloudFront (CDN + HTTPS + WAF)
├── /api/* → Application Load Balancer
└── /* → S3 (React app)
│
▼
ALB (across 2+ AZs)
│
▼
ECS Fargate (2+ tasks, auto-scaling)
│
├──→ RDS PostgreSQL (Multi-AZ) [private subnet]
├──→ ElastiCache Redis [private subnet, for sessions]
└──→ S3 (file uploads, signed URLs)
Monitoring/Ops:
CloudWatch (metrics, logs, alarms)
CloudTrail (API audit log)
X-Ray (distributed tracing)
SNS → PagerDuty/Slack (alerts)
CI/CD:
GitHub → GitHub Actions → ECR → ECS deploy
IaC:
CDK stack defines everything above
Changes via PR → review → cdk deploy
Frequently Asked Questions
My AWS bill is too high. How do I find what's costing money?
Use Cost Explorer (Billing → Cost Explorer) to break down costs by service, region, and resource. Sort by 'Service' to find the biggest line items. Enable Cost Allocation Tags to track costs per project/team/environment. Use 'Trusted Advisor' for automated recommendations. The most common surprise costs: forgotten EC2 instances, unattached EBS volumes, NAT Gateway data transfer, and unused Elastic IPs.