4.1 Compute Cost Optimization — Right-Sizing, RIs, Savings Plans, and Spot
Key Takeaways
- Right-sizing means choosing the smallest instance type that meets your performance requirements — AWS Cost Explorer and Compute Optimizer provide recommendations.
- Reserved Instances (1 or 3 year) save up to 72% for steady-state workloads; Savings Plans provide similar savings with more flexibility across instance types and Regions.
- Spot Instances save up to 90% for fault-tolerant workloads; Spot Fleets can mix Spot and On-Demand to maintain target capacity.
- Lambda pricing is per-invocation and per-millisecond of compute time — it is cost-effective for sporadic, event-driven workloads compared to always-running EC2.
- Auto Scaling ensures you pay only for the capacity you need by dynamically adjusting instance count to match demand.
Compute Cost Optimization — Right-Sizing, RIs, Savings Plans, and Spot
Quick Answer: Right-size instances first (use Compute Optimizer). Then apply pricing models: Reserved Instances or Savings Plans for steady-state (up to 72% off), Spot for fault-tolerant (up to 90% off), and Auto Scaling to match capacity to demand. Consider Lambda for sporadic workloads to avoid paying for idle compute.
Cost Optimization Strategy
The compute cost optimization hierarchy:
- Right-size — Ensure you are not over-provisioning
- Auto Scale — Match capacity to demand (never pay for idle)
- Pricing model — Apply the right pricing for each workload
- Architecture — Consider serverless (Lambda, Fargate) for variable workloads
Right-Sizing
Right-sizing means matching instance types and sizes to your workload's actual resource needs.
Tools for Right-Sizing
| Tool | What It Does |
|---|---|
| AWS Compute Optimizer | ML-based recommendations for EC2, ASG, Lambda, EBS, Fargate |
| AWS Cost Explorer | Right-sizing recommendations based on utilization data |
| CloudWatch Metrics | Monitor CPU, memory, network, disk utilization |
| AWS Trusted Advisor | Identifies underutilized EC2 instances |
Common Right-Sizing Patterns
| Signal | Action |
|---|---|
| CPU consistently <20% | Downsize to a smaller instance type |
| Memory consistently <30% used | Switch to a compute-optimized (C-series) instead of memory-optimized (R-series) |
| Network throughput maxed out | Upsize or switch to enhanced networking instance |
| Burst credits accumulating on T-series | Consider switching to a smaller instance or right-sizing |
Pricing Model Comparison
| Model | Discount | Commitment | Best For |
|---|---|---|---|
| On-Demand | 0% | None | Short-term, unpredictable, testing |
| Reserved Instance | Up to 72% | 1 or 3 years | Steady-state 24/7 workloads (databases) |
| Savings Plan | Up to 72% | 1 or 3 years ($/hr) | Flexible commitment across services |
| Spot Instance | Up to 90% | None | Fault-tolerant batch, analytics, CI/CD |
| Dedicated Host | Varies | On-Demand or Reserved | License compliance (BYOL) |
Reserved Instances Deep Dive
| Payment Option | Discount Level |
|---|---|
| All Upfront | Highest discount |
| Partial Upfront | Medium discount |
| No Upfront | Lowest discount (but still significant) |
| Term | Standard RI Discount | Convertible RI Discount |
|---|---|---|
| 1 Year | ~40% | ~33% |
| 3 Year | ~60-72% | ~54-66% |
Key: Standard RIs offer higher discounts but are locked to specific instance types. Convertible RIs can be exchanged for different instance types, families, OS, or tenancy.
Savings Plans Deep Dive
| Plan | Covers | Flexibility |
|---|---|---|
| Compute Savings Plan | EC2, Lambda, Fargate | Any family, size, OS, tenancy, Region |
| EC2 Instance Savings Plan | EC2 only | Fixed family + Region; flexible size + OS |
| SageMaker Savings Plan | SageMaker | ML workload optimization |
How it works: You commit to a consistent amount of compute usage (measured in $/hour) for 1 or 3 years. Any usage above your commitment is billed at On-Demand rates.
On the Exam: "Most flexible cost savings for compute" → Compute Savings Plan. "Highest savings for a specific EC2 instance family" → EC2 Instance Savings Plan or Standard RI.
Spot Instance Strategies
| Strategy | Description |
|---|---|
| Spot Fleet | Request a mix of Spot and On-Demand instances to maintain target capacity |
| Diversify | Use multiple instance types and AZs to reduce interruption risk |
| Spot + On-Demand mix | On-Demand for baseline capacity, Spot for peak capacity |
| Interruption handling | Design for 2-minute interruption notice; checkpoint and resume |
Serverless Cost Optimization
| Scenario | EC2 Cost | Lambda Cost | Winner |
|---|---|---|---|
| 10 requests/day, 1 sec each | $50+/month (t3.micro 24/7) | ~$0.00 (within free tier) | Lambda |
| 1 million requests/day, steady | $150/month (m5.large) | ~$60/month | Lambda |
| 100 million requests/day, steady | $1,500/month (multiple EC2) | ~$6,000/month | EC2 (with RIs) |
Rule of thumb: Lambda is more cost-effective for variable, sporadic workloads. EC2 with Reserved pricing is more cost-effective for high-volume, steady-state workloads.
Auto Scaling for Cost Optimization
Auto Scaling is not just for availability — it is a core cost optimization tool:
- Scale in during low demand → reduce instance count → reduce cost
- Scale out during high demand → meet demand without over-provisioning
- Scheduled scaling → scale down during nights/weekends for business-hours apps
- Target tracking → maintain steady utilization (e.g., 70% CPU) without waste
A company runs a database 24/7 on an m5.2xlarge EC2 instance with consistent utilization. They want to reduce costs without changing the instance. What pricing model provides the HIGHEST savings?
A company wants to optimize costs across EC2, Lambda, and Fargate without locking into specific instance types. Which pricing model should they use?
An application processes images uploaded by users. Processing takes 30 seconds per image and uploads are sporadic (0-1000 per hour). Which compute option is MOST cost-effective?