AWS · Production

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.

Advanced 5 min Lesson 25 of 30
Before you start:Introduction to AWS
0/30 in AWS
On this page · 5 min · Advanced

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#

ShellFind common waste Illustrative
# 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
Expected output
-------------------------------------------------
|               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#

  1. Available volumes are not attached to any instance but are still billed.
  2. Unassociated Elastic IPs are charged.
  3. 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#

Buying commitments before right-sizing

Right-size first, then commit — otherwise you lock in waste.

Ignoring data transfer

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
Text Illustrative
Spot Instances (or Fargate Spot) — large discount, and interruptions are acceptable because the job can retry.

Mini quiz#

Cost Optimization quizMultiple choice Question 1 of 1

What should you do before buying a Savings Plan?

Score so far: 0/0

Want more? Practise all AWS MCQs · AWS interview questions

My notes#

Saved in this browser.

Progress is saved in this browser. Sign in to sync.