Cost Optimisation

Controlling AWS spend — how AWS bills (compute, storage, requests and data transfer), visibility with Cost Explorer, budgets, anomaly detection and tagging, right-sizing, Savings Plans, Reserved Instances and Spot, storage and database savings, the hidden costs of NAT gateways and cross-AZ traffic, serverless economics, and FinOps practices.

Intermediate 6 min readLesson 18 of 19 Interview Q&A

The cloud's pay-as-you-go model cuts both ways: you never pay for idle hardware you bought — but you pay for everything you forget. Cost is an architectural property, like latency or availability, and engineers make the decisions that drive it.

How AWS charges

DimensionExamples
Compute timeEC2 per second, Fargate per vCPU-second and GB-second, Lambda per GB-second
Provisioned capacityRDS instances, provisioned IOPS, DynamoDB provisioned capacity, NAT gateway and load balancer hours
StoragePer GB-month: S3 by class, EBS by type, snapshots, logs
RequestsS3 PUT/GET, API Gateway, Lambda invocations, DynamoDB on-demand reads and writes, KMS calls
Data transferOut to the internet; between AZs; between regions; through NAT gateways

Inbound data from the internet is free; outbound is not, and traffic between AZs is charged in both directions. Data transfer is the line item that surprises most teams.

Visibility first

  1. Cost Explorer: spend by service, account, region, usage type and tag; forecasts. Turn on hourly or resource-level granularity for detail.
  2. Tag everything (team, service, env) and activate them as cost allocation tags; enforce with tag policies and IaC defaults.
  3. AWS Budgets with alerts at 50/80/100% of forecast — per account and per team.
  4. Cost Anomaly Detection emails or Slacks you when spend deviates from the pattern — catches runaway resources in hours, not at month end.
  5. Cost and Usage Report (CUR 2.0 / data exports) to S3, queried with Athena or visualised in QuickSight for detailed analysis.
  6. Compute Optimizer and Trusted Advisor recommend right-sizing and flag idle resources.

Show each team its own costs. What gets measured and owned gets managed.

The levers, roughly by impact

1. Stop paying for nothing

  • Idle or forgotten resources: dev environments running nights and weekends (schedule them off — that's ~65% of the hours in a week), unattached EBS volumes, old snapshots, unused Elastic IPs, idle load balancers and NAT gateways, orphaned test stacks.
  • Log groups without retention, S3 buckets without lifecycle rules, incomplete multipart uploads.

2. Right-size

Most instances are over-provisioned "just in case". Use Compute Optimizer and actual utilisation (p95 CPU and memory over weeks) to step down a size or switch families. Move to current generations and Graviton for better price-performance. For Lambda, tune memory with Power Tuning (Lambda). For containers, set task sizes from measured usage.

3. Commit for the baseline

OptionFlexibilityDiscountNotes
Compute Savings PlansAny EC2 family, size, region, OS; also Fargate and LambdaUp to ~66%The safest commitment
EC2 Instance Savings PlansOne family in one regionUp to ~72%Higher discount, less flexible
Reserved InstancesSpecific type and regionSimilar to Savings PlansStill the mechanism for RDS, ElastiCache, OpenSearch, Redshift
Database Savings PlansManaged database usageVariesNewer option for database spend

Commit to the steady floor of usage you're confident about (look at the minimum over recent months), not the peak, and layer commitments over time rather than buying everything at once. 1-year no-upfront is the low-risk starting point.

4. Use Spot for interruptible work

Spot capacity costs up to ~90% less. Good for CI runners, batch and data processing, stateless web tiers (mixed with On-Demand), dev environments and ML training with checkpoints. Diversify instance types and use capacity-optimised allocation (EC2).

5. Storage and databases

  • S3 lifecycle rules and Intelligent-Tiering; compress and batch small objects (S3).
  • gp3 instead of gp2 (typically ~20% cheaper with better baseline performance); delete old snapshots (EBS and EFS).
  • Aurora Serverless v2 or stopping non-production databases off-hours; Aurora I/O-Optimized if I/O dominates the bill.
  • DynamoDB: on-demand for spiky or unknown traffic, provisioned with auto scaling for steady traffic, Standard-IA table class for rarely read tables.
  • Cache hot reads (CloudFront, ElastiCache, DAX) — cheaper than scaling databases (Caching).

6. Architecture and data transfer

expensivecheapApp in private subnetNAT gatewayper-GB processingS3 gateway endpointfreeS3
  • VPC endpoints for S3 and DynamoDB (free gateway endpoints) instead of NAT; interface endpoints for heavy ECR or other service traffic (VPC).
  • Keep chatty services and their databases in the same AZ path where you can (zone-aware routing), and avoid pointless cross-AZ hops — but never sacrifice multi-AZ resilience to save transfer costs.
  • Serve users through CloudFront — its data-transfer rates are lower than direct S3/EC2 egress, and cache hits avoid origin work.
  • Compress responses; avoid sending the same large payloads repeatedly.

Serverless vs servers economics

Serverless costs scale with usage; servers cost the same whether busy or idle.

  • Low or spiky traffic → Lambda, Fargate, DynamoDB on-demand and Aurora Serverless are usually cheapest — idle costs nothing.
  • Sustained high throughput → containers or EC2 with Savings Plans are often several times cheaper per request.
  • Count engineering time too: a slightly higher bill that removes patching, scaling and on-call work is often the better trade.

FinOps as a practice

  • Inform → optimise → operate: visibility and allocation, then improvements, then continuous governance.
  • Include cost in design reviews: "what does this cost at 10× traffic?" (Back-of-the-envelope estimation).
  • Track unit economics: cost per order, per active user, per 1,000 API calls — a rising total bill is fine if cost per unit falls.
  • Guardrails: SCPs blocking very expensive instance types in dev, budget actions, auto-shutdown for sandboxes.
Interview questions
QYour AWS bill jumped 40% this month. How do you investigate?medium

Open Cost Explorer and group by service, then by account, region and usage type, comparing with the previous month to find which line items grew; check Cost Anomaly Detection alerts. Drill into the specific resources with resource-level data or the Cost and Usage Report — common culprits are new or forgotten instances, data transfer through NAT gateways or across AZs or regions, log ingestion, a runaway Lambda or retry loop, DynamoDB on-demand spikes, or snapshots accumulating. Correlate with deploys, traffic changes and CloudTrail for who created what, fix the cause, and add budgets, alarms or tags to catch it next time.

QSavings Plans vs Reserved Instances vs Spot?easy

Savings Plans commit to a spend per hour for one or three years in exchange for discounts, and Compute Savings Plans apply flexibly across EC2 families, regions, Fargate and Lambda. Reserved Instances commit to a specific instance configuration and are still how you discount services like RDS and ElastiCache. Spot uses spare capacity at the deepest discounts with no commitment, but instances can be reclaimed with two minutes' notice, so it suits fault-tolerant workloads. A typical mix is commitments for the baseline, On-Demand for peaks and Spot for interruptible work.

Key takeaways
  • AWS bills for compute time, provisioned capacity, storage, requests and data transfer — outbound and cross-AZ transfer surprise many teams.
  • Get visibility first: Cost Explorer, cost allocation tags, budgets, anomaly detection and per-team ownership.
  • Biggest levers: remove idle resources, right-size (and move to Graviton), commit with Savings Plans for the baseline, use Spot for interruptible work.
  • Save on storage with lifecycle rules and gp3; on networking with VPC endpoints, zone awareness and CloudFront.
  • Serverless is cheapest for spiky or low traffic; reserved servers for sustained high throughput — include engineering time.
  • Treat cost as an architectural metric and track unit economics.