Cost Optimization
AWS bills by the second, so small habits make a big difference. These are the techniques teams use to keep costs under control.
On this page · 5 min · Advanced
On this page
- Learning objectives
- Explanation
- Code example
- Step by step
- Real-world use
- Common mistakes
- Best practices
- Remember this
- Practice exercise
- Mini quiz
- Related topics
- My notes
- Reading time
- 5 min
- Difficulty
- Advanced
- Updated
- Oct 29, 2026
Related tutorials
Learning objectives#
- Track costs with Budgets and Cost Explorer
- Find idle and oversized resources
- Use Savings Plans and Spot
- Optimise storage and data transfer
Explanation#
AWS Budgets alerts on actual or forecast spend. Cost Explorer breaks down costs by service, account and cost-allocation tag.
Common waste: idle EC2 instances, unattached EBS volumes, old snapshots, unused Elastic IPs, NAT gateway traffic, and logs without retention.
Savings Plans (1 or 3 years) discount steady compute; Spot Instances use spare capacity at a large discount for interruption-tolerant work; Graviton (ARM) instances often give better price-performance.
S3 Intelligent-Tiering and lifecycle rules reduce storage cost; CloudFront can reduce data-transfer cost from origins.
Code example: Find common waste#
# Unattached EBS volumes
aws ec2 describe-volumes --filters Name=status,Values=available \
--query "Volumes[].{Id:VolumeId,GB:Size,Created:CreateTime}" --output table
# Elastic IPs not associated with anything
aws ec2 describe-addresses --query "Addresses[?AssociationId==null].PublicIp" --output text
# Last month's cost by service
aws ce get-cost-and-usage --time-period Start=2026-09-01,End=2026-10-01 \
--granularity MONTHLY --metrics UnblendedCost --group-by Type=DIMENSION,Key=SERVICE
------------------------------------------------- | DescribeVolumes | +----------------------------+-------+----------+ | Created | GB | Id | +----------------------------+-------+----------+ | 2026-03-14T08:21:11.000Z | 100 | vol-0a1b | +----------------------------+-------+----------+
This example is illustrative. Copy or download it and run it in your own environment; the expected output is shown above.
Step-by-step explanation#
- Available volumes are not attached to any instance but are still billed.
- Unassociated Elastic IPs are charged.
- Cost Explorer shows which services drive the bill.
Real-world use case#
A monthly “cost review” where the team deletes waste, right-sizes using Compute Optimizer, and buys Savings Plans for the steady baseline.
Common mistakes#
Right-size first, then commit — otherwise you lock in waste.
Cross-AZ, NAT and internet egress traffic can be a large part of the bill.
Best practices#
- Budgets and anomaly detection on every account
- Activate cost-allocation tags
- Schedule non-production resources off-hours
- Review Compute Optimizer and Trusted Advisor
Remember this#
Measure (Cost Explorer) → remove waste → right-size → commit.
Spot = cheap but interruptible.
Idle still bills: EBS, EIPs, NAT, logs.
Practice exercise#
Your task: Which pricing option suits a nightly batch job that can be retried if interrupted?
Show solution
Spot Instances (or Fargate Spot) — large discount, and interruptions are acceptable because the job can retry.
Mini quiz#
What should you do before buying a Savings Plan?
Want more? Practise all AWS MCQs · AWS interview questions
My notes#
Saved in this browser.