Cost optimization in practice

Amazon Web Services · Advanced · 16 min

At scale, a few architectural and purchasing decisions routinely save 30 to 60 percent of a cloud bill.

Cost optimization works in a loop: see spend, reduce waste, commit for discounts, and architect for efficiency.

Visibility: tag consistently and activate the tags, export detailed billing data (CUR 2.0 via Data Exports) to query with Athena, and enable Cost Anomaly Detection to get alerted when a service's spend jumps. Track unit costs, such as cost per order, not just the total.

Waste: idle and oversized resources. Compute Optimizer recommends instance, EBS, Lambda and ECS sizes from utilisation. Schedule non-production environments off at night, delete unattached volumes, old snapshots and AMIs, and migrate gp2 volumes to gp3.

Purchase options:

  • Savings Plans: commit to a dollar amount per hour for 1 or 3 years. Compute Savings Plans (up to about 66% off) apply flexibly across EC2 families, Regions, Fargate and Lambda; EC2 Instance Savings Plans (up to about 72%) are tied to a family in a Region. Cover the steady baseline, not peaks.
  • Reserved Instances remain the mechanism for RDS, ElastiCache, OpenSearch and Redshift.
  • Spot capacity is up to 90% cheaper but can be reclaimed with a 2-minute warning. Use it for stateless, fault-tolerant work: CI, batch, containers. Diversify instance types and use capacity-optimised allocation.

Architecture: Graviton instances and arm64 Lambdas, S3 Intelligent-Tiering and lifecycle rules, gateway endpoints instead of NAT for S3 traffic, CloudFront in front of origins, same-AZ traffic where it is safe, right log retention, and serverless for spiky low-volume workloads.

Example

# Rightsizing findings from Compute Optimizer
aws compute-optimizer get-ec2-instance-recommendations \
  --query 'instanceRecommendations[].[instanceArn,finding,recommendationOptions[0].instanceType]' \
  --output text
# arn:aws:ec2:eu-west-1:111122223333:instance/i-0a1b...  Overprovisioned  m7g.large

# What Compute Savings Plan commitment would AWS suggest?
aws ce get-savings-plans-purchase-recommendation --savings-plans-type COMPUTE_SP \
  --term-in-years ONE_YEAR --payment-option NO_UPFRONT --lookback-period-in-days THIRTY_DAYS \
  --query 'SavingsPlansPurchaseRecommendation.SavingsPlansPurchaseRecommendationSummary.[HourlyCommitmentToPurchase,EstimatedSavingsPercentage]'

# gp2 -> gp3: same or better performance, lower price, online
for v in $(aws ec2 describe-volumes --filters Name=volume-type,Values=gp2 \
             --query 'Volumes[].VolumeId' --output text); do
  aws ec2 modify-volume --volume-id "$v" --volume-type gp3
done

# Alert on unusual spend per service
aws ce create-anomaly-monitor --anomaly-monitor \
  '{"MonitorName": "per-service", "MonitorType": "DIMENSIONAL", "MonitorDimension": "SERVICE"}'

Remember

  • Loop: visibility, waste removal, commitments, architecture
  • Savings Plans cover the steady baseline; Spot for interruptible work
  • Rightsize with Compute Optimizer; move to Graviton and gp3
  • Data transfer and NAT are architecture problems, not purchasing ones

Watch out for

  • Buying commitments for peak usage, leaving them under-used when load drops.

Check yourself

  1. A fleet runs steadily on EC2, Fargate and Lambda and might move Regions next year. Which commitment fits?
  2. Which workload is the best fit for Spot?

Sign in to answer, see the explanations, and get this lesson back as a quick review later.

Official docs: docs.aws.amazon.com/cost-management/latest/userguide/what-is-costmanagement.html

Builds on

Unlocks

Nothing builds on this yet.