Cost optimization
How to buy EC2 (On-Demand, Savings Plans, Reserved, Spot), cheap storage classes, data transfer costs and cost monitoring tools.
- DomainCost-optimized architectures
- 9 diagrams
- 11 scenarios
- 13 services
5-minute essentials
- On-Demand: pay per second / hour, no commitment.Suits short-term, unpredictable or experimental workloads. It is the highest price, used as the baseline for comparison.
- Savings Plans: commit to spending a fixed USD amount per hour for 1 or 3 years in exchange for lower prices than On-Demand.Compute Savings Plans are the most flexible (any family, Region, OS; plus Fargate and Lambda). EC2 Instance Savings Plans discount more deeply but are tied to one family in one Region.
- Reserved Instances: reserve a specific configuration for 1 or 3 years. Standard discounts more deeply and can be resold on the Marketplace; Convertible can be exchanged for another configuration.RDS, ElastiCache, Redshift and OpenSearch still have their own reserved pricing; if the question says a database runs steadily 24/7 → reserved / Database Savings Plans.
- Spot Instances: use spare EC2 capacity, up to 90% off, but AWS can reclaim them with only a 2-minute warning.Suits interruption-tolerant work: batch, image processing, CI, EMR task nodes, stateless workers. Not for databases or work that cannot stop.
- Combine: buy Savings Plans / RI for the steady base, run the fluctuating part On-Demand, run interruption-tolerant work on Spot.An Auto Scaling group with a mixed instances policy blends On-Demand and Spot, using several instance types to reduce reclaim risk.
- Dedicated Host: an entire physical server just for you, with visible sockets / cores.When the question mentions software licensing per socket / core (BYOL) or compliance requirements → Dedicated Host.
- Rightsize before committing: Compute Optimizer recommends better-fitting instances, EBS volumes and Lambda settings.Committing to Savings Plans for oversized instances locks in the waste for 1–3 years.
- S3: pick the storage class by access frequency and use lifecycle rules to transition / delete automatically.Standard-IA and One Zone-IA bill a 30-day minimum, Glacier Instant / Flexible 90 days, Deep Archive 180 days; IA bills a 128 KB minimum per object.
- S3 Intelligent-Tiering when the access pattern is unknown: it moves tiers automatically, with no retrieval fees, only a per-object monitoring fee.Objects smaller than 128 KB are not monitored and always stay in the Frequent tier.
- Data transfer: data out to the internet and between AZs / Regions is charged; the first 100 GB per month out to the internet is free (aggregated across all services).To reduce it: CloudFront caches near users, gateway endpoints for S3 / DynamoDB instead of going through NAT, keep "chatty" traffic within the same AZ when reasonable.
- NAT Gateway is billed per hour and per GB processed.Heavy traffic from a private subnet to S3 / DynamoDB: use a gateway endpoint (free) instead of going through NAT.
- Cost Explorer views and forecasts costs and suggests Savings Plans / RI purchases. Budgets sets thresholds, sends alerts and can run actions automatically."Alert when cost is about to exceed" → Budgets; "analyze trends, find which service costs the most" → Cost Explorer.
- Cost and Usage Report (Data Exports) is the most detailed cost data, exported to S3 and queried with Athena.Attach cost allocation tags to split costs by project / department.
- AWS Organizations consolidated billing: combines usage across accounts to reach tiered pricing and shares Savings Plans / RI between accounts.When the question mentions many accounts, one bill and shared discounts → Organizations.
- Turn off what you do not use: dev environments outside working hours, orphaned EBS volumes / snapshots, Elastic IPs and public IPv4 addresses (all billed hourly).Trusted Advisor and Cost Optimization Hub list idle or underused resources.
Diagrams
Mixing purchase options by load shape
Step by step
- Savings Plans apply automatically to continuous usage: commit to the base, not the peak.
- At peak, add On-Demand instances, paid per second, and drop them when the peak ends.
- Interruption-tolerant work runs on Spot, spread across instance types / AZs to reduce simultaneous reclaims.
Handling the Spot interruption warning (2 minutes)
S3 lifecycle: transition classes by data age
Step by step
- After 30 days of little reading: Standard-IA, still readable immediately but with a retrieval fee.
- The older it gets, the cheaper the class; Glacier Flexible must be restored before reading.
- Long-term storage in Deep Archive, then automatic deletion when retention ends.
Reaching S3 via NAT or a gateway endpoint
Step by step
- Without an endpoint: every GB to S3 incurs NAT processing fees.
- Add a gateway endpoint to the private subnet's route table: traffic to S3 goes directly, with no endpoint charge.
CloudFront cuts origin load and cost
Step by step
- Users download from the nearest edge.
- The origin serves only cache misses and dynamic requests.
AWS Budgets: alerts and automatic actions
Step by step
- Forecast cost exceeds 80% of the budget: send an alert.
- Budget exceeded: the budget action applies a policy that blocks creating new resources.
Detailed cost reporting: CUR + Athena
Step by step
- Enable cost allocation tags so tags appear in the cost report.
- The detailed report is written to S3.
- Athena queries cost by project, and a dashboard displays it for finance.
Organizations: one bill, shared discounts
Step by step
- Costs from all accounts merge into one bill; usage is pooled to reach tiered pricing.
- Savings Plans bought in prod but not fully used automatically apply to dev (unless sharing is turned off).
Choosing how to buy EC2
Step by step
- Video rendering, CI, batch data processing: Spot, mixing several instance types to reduce reclaims.
- Always-on base load that may change instance family or move to containers: Compute Savings Plans are the most flexible.
- Short-term, unpredictable load: On-Demand, paid per second, no commitment.
Quick comparisons
Ways to buy EC2
| On-Demand | Savings Plans | Reserved Instances | Spot | |
|---|---|---|---|---|
| Commitment | None | USD / hour, 1 or 3 years | Specific configuration, 1 or 3 years | None |
| Discount (max) | 0% | Compute up to 66%, EC2 Instance up to 72% | Standard deeper than Convertible | Up to 90% |
| Flexibility | Highest | Compute: any family / Region / Fargate / Lambda | Convertible can be exchanged; Standard can be resold | Can be reclaimed, 2-minute warning |
| Use when | Short-term, unpredictable | Steady base, architecture may change | Steady base, fixed configuration | Interruption-tolerant work |
S3 storage classes by cost
| Class | Access | Minimum storage | Notes |
|---|---|---|---|
| Standard | Frequent, milliseconds | None | ≥ 3 AZs |
| Intelligent-Tiering | Unknown in advance | None | Per-object monitoring fee, no retrieval fee |
| Standard-IA | Infrequent, still needs milliseconds | 30 days, 128 KB | Per-GB retrieval fee |
| One Zone-IA | Infrequent, re-creatable data | 30 days, 128 KB | Only 1 AZ |
| Glacier Instant Retrieval | About once a quarter, milliseconds | 90 days, 128 KB | Retrieval fee |
| Glacier Flexible Retrieval | About once a year, minutes to hours | 90 days | Must restore before reading |
| Glacier Deep Archive | Less than once a year, hours | 180 days | Cheapest; must restore |
Cost management tools
| Tool | What it does | Commonly asked |
|---|---|---|
| Cost Explorer | View, filter and forecast costs; suggests Savings Plans / RI | Which service is driving cost up? How many Savings Plans should I buy? |
| Budgets | Thresholds on cost / usage / RI and SP coverage; alerts; actions | Alert when about to exceed budget, automatically apply a blocking policy |
| Cost and Usage Report / Data Exports | Line-item detail exported to S3 | Analyze with Athena, custom dashboards |
| Compute Optimizer | Rightsizing recommendations for EC2, EBS, Lambda, ECS | Underused instances, picking a cheaper instance type |
| Trusted Advisor | Checks for idle resources and suboptimal configuration | Find unattached EBS volumes, spare EIPs, etc. |
| Pricing Calculator | Estimates cost before building | Quote a new architecture |
Reducing data transfer cost
| Situation | Cheaper way |
|---|---|
| Private subnet reading / writing a lot of S3 / DynamoDB | Gateway endpoint instead of NAT Gateway |
| Global users downloading static content | CloudFront caching at the edge |
| Two services exchanging a lot of data | Place them in the same AZ if it does not hurt high-availability requirements |
| Backing up to another Region | Copy only what is needed, compress, choose a cheap storage class at the destination |
Exam scenarios
1An application runs steadily 24/7 on EC2 for the next 3 years, but the team wants to be able to change instance family and move part of it to Fargate.
Show answer
Right: 3-year Compute Savings Plans
Apply to EC2 of any family / Region and also to Fargate and Lambda.
Wrong: Standard Reserved Instances
Tied to a configuration, do not apply to Fargate.
Wrong: EC2 Instance Savings Plans
Tied to one family in one Region, do not include Fargate.
2Thousands of images must be processed every night; the job can be redone if stopped midway; wants the cheapest option.
Show answer
Right: Spot Instances (e.g. AWS Batch or Auto Scaling with Spot, several instance types)
Interruption-tolerant work, up to 90% off.
Wrong: On-Demand
Works but costs much more.
Wrong: Reserved Instances
You pay for the whole day although it runs only a few hours.
3A website has a steady base load of 10 instances and needs up to 30 more for a few hours at peak.
Show answer
Right: Savings Plans / RI for the 10-instance base, On-Demand (and Spot if interruption is tolerable) for the peak via Auto Scaling
Each part of the load uses the purchase option that fits it.
Wrong: Buy Savings Plans for 40 instances
You pay for peak capacity even off-peak.
4Logs must be kept for 7 years by regulation; they are viewed often in the first 30 days, afterwards almost never, and waiting a few hours is acceptable if needed.
Show answer
Right: Lifecycle: Standard for 30 days → Glacier Deep Archive, delete after 7 years
Deep Archive is the cheapest for data that can wait a few hours to restore.
Wrong: Leave it in S3 Standard
Pays a high price for data that is almost never read.
Wrong: One Zone-IA for everything
Compliance data should not sit in a single AZ; still costlier than Glacier.
5A bucket holds millions of objects with unpredictable access patterns.
Show answer
Right: S3 Intelligent-Tiering
Moves tiers automatically by access, no retrieval fees.
Wrong: Write your own transition job based on access logs
High operational effort and error-prone.
6The NAT Gateway bill is very high because EC2 instances in a private subnet download large amounts of data from S3 in the same Region.
Show answer
Right: A gateway endpoint for S3 and add a route to the private subnet's route table
Traffic to S3 bypasses NAT; gateway endpoints are free.
Wrong: Switch to a NAT instance
Still pays for data transfer, plus extra operations work.
7Data transfer out to the internet is expensive because global users download images and video from EC2.
Show answer
Right: Put CloudFront in front, move static content to S3 as the origin
Content is cached at the edge, fewer fetches from the origin; users are also faster.
Wrong: Increase the instance size
Does not reduce the amount of data going out to the internet.
8Management wants an email when the monthly cost is forecast to exceed 80% of the budget, and to automatically block new resource creation once it is exceeded.
Show answer
Right: AWS Budgets with an 80% forecast alert (SNS / email) and a budget action applying an IAM policy or SCP
Budgets supports actual and forecast thresholds, plus automatic actions.
Wrong: Cost Explorer
For viewing and analysis; it does not send threshold alerts.
Wrong: CloudWatch billing alarm
Only alerts on actual incurred cost, with no forecast or actions like Budgets.
9A company has 30 AWS accounts and wants one bill, and Savings Plans bought in one account to be used by the others.
Show answer
Right: AWS Organizations with consolidated billing
One bill, tiered discounts computed on total usage, Savings Plans / RI shared between accounts.
Wrong: Each account buys its own Savings Plans
Easy to have a surplus in one place and a shortage in another.
10Finance needs to split costs by project and build detailed reports with SQL.
Show answer
Right: Attach cost allocation tags per project, export Cost and Usage Report (Data Exports) to S3, query with Athena
CUR is the most detailed data and has tag columns.
Wrong: Read the monthly PDF invoice
Not detailed enough, does not split by project.
11Licensed database software is priced per physical core, and the company wants to use its existing license on EC2.
Show answer
Right: EC2 Dedicated Host
Exposes physical sockets / cores, so per-core BYOL licenses can be used.
Wrong: Dedicated Instances
Dedicated hardware, but sockets / cores are not visible or controllable for licensing.
Quick picks
Where do you optimize cost first?
| When you need | Use |
|---|---|
| Continuous base load, may change family / move to Fargate | Compute Savings Plans · see diagram |
| Fixed base load on one family in one Region | EC2 Instance Savings Plans or Standard RI · see diagram |
| Interruption-tolerant work | Spot (several instance types, handle the 2-minute warning) · see diagram |
| Licensing per socket / core | Dedicated Host |
| Data gets read less as it ages | S3 lifecycle to IA / Glacier · see diagram |
| Unknown access pattern | S3 Intelligent-Tiering |
| High NAT fees from traffic to S3 / DynamoDB | Gateway endpoint · see diagram |
| High data transfer out to the internet | CloudFront · see diagram |
| Alert / block when about to exceed budget | AWS Budgets + budget action · see diagram |
| Detailed cost reports by tag | Cost and Usage Report + Athena · see diagram |
| Many accounts, one bill, shared discounts | Organizations consolidated billing · see diagram |
| Instances using few resources | Compute Optimizer (rightsizing) before committing |
Common pitfalls
- Using Spot for databases or work that cannot be stopped midway.
- Buying Savings Plans / RI for peak load instead of the base load.
- Committing before rightsizing: locks in waste for 1–3 years.
- Choosing Standard RI when you know the family will change: Convertible RI or Compute Savings Plans fit better.
- Transitioning small or short-lived objects to Standard-IA / Glacier: you get billed the 128 KB minimum and 30 / 90 / 180 days.
- Choosing Glacier Flexible Retrieval / Deep Archive for data that must be read immediately: you must restore and wait minutes to hours.
- Sending all S3 traffic through a NAT Gateway instead of the free gateway endpoint.
- Forgetting inter-AZ data transfer fees when designing services that exchange a lot of data.
- Using Cost Explorer when the question needs threshold alerts: that is Budgets.
- Forgetting unused EBS volumes, snapshots and Elastic IPs: they still cost money.
- Thinking Dedicated Instances solve per-core licensing: you need a Dedicated Host.
Services in this module
Savings Plansusage commitment for discounts
Cost Explorercost analysis charts
Budgetsbudgets and cost alerts
Cost and Usage Reportmost detailed billing data
Compute Optimizerright-sizing recommendations
- Pricing Calculatorestimate costs before you build
Trusted Advisorautomated account optimization advice
Organizationsmanage multiple accounts
EC2virtual servers
EC2 Auto Scalingauto add/remove servers
S3unlimited object storage
S3 Glacierlow-cost long-term archive
CloudFrontCDN, cache near users
Numbers that change (checked against AWS docs)
- Spot Instances are up to 90% cheaper than On-Demand. checked 2026-10-16 ↗
- The Spot interruption warning is issued 2 minutes before the instance is stopped / terminated (via EventBridge and instance metadata). checked 2026-10-16 ↗
- There are 4 Savings Plans types: Compute (up to 66%, covers EC2, Fargate, Lambda), EC2 Instance (up to 72%, one family in one Region), Database (up to 35%), SageMaker AI (up to 64%). checked 2026-10-16 ↗
- Savings Plans have 1- or 3-year terms, paid All upfront / Partial upfront / No upfront. checked 2026-10-16 ↗
- Standard RIs cannot be exchanged but can be sold on the RI Marketplace; Convertible RIs can be exchanged but not sold on the Marketplace. checked 2026-10-16 ↗
- AWS Budgets updates its data up to 3 times a day; alerts are based on actual or forecast cost, sent by email / SNS. checked 2026-10-16 ↗
- S3 Standard-IA and One Zone-IA: 30-day and 128 KB minimums; Glacier Instant / Flexible Retrieval: 90 days; Deep Archive: 180 days. checked 2026-10-16 ↗
- S3 Intelligent-Tiering has no retrieval fees; objects under 128 KB are not monitored and always stay in the Frequent Access tier. checked 2026-10-16 ↗
- The first 100 GB of data out to the internet each month is free (aggregated across all services and Regions, excluding China and GovCloud). checked 2026-10-16 ↗
- A gateway endpoint for S3 has no additional charge. checked 2026-10-16 ↗
- Every public IPv4 address attached to a resource in a VPC is billed hourly, including Elastic IPs in use. checked 2026-10-16 ↗
- An On-Demand Capacity Reservation holds EC2 capacity in one AZ, can be used immediately with no commitment, and gives no discount by itself; combine with Savings Plans or Regional RIs to get a discount. checked 2026-10-19 ↗