Managing Cost
Keep the bill predictable with right-sizing, cleanup, budgets, and commitment discounts.
AWS bills for what you use, so cost is an engineering concern. A few habits keep it under control.
Cost levers
- Right-size — match instance/task size to real usage; do not over-provision.
- Clean up — delete idle Elastic IPs, old snapshots, and unused load balancers.
- Commit — Savings Plans and Reserved capacity cut steady-state costs sharply.
- Serverless for spiky loads — Lambda costs nothing when idle.
Guardrails
Set AWS Budgets with alerts so a runaway resource emails you before it becomes a shocking invoice. Tag resources by team or environment to see where money goes.
Example
{
"BudgetName": "myapp-monthly",
"BudgetLimit": { "Amount": "200", "Unit": "USD" },
"TimeUnit": "MONTHLY",
"BudgetType": "COST",
"CostFilters": { "TagKeyValue": ["user:project$myapp"] }
}When to use it
- A team receives a Budget alert when monthly AWS spend crosses 80% of the $500 limit so they can investigate before the bill arrives.
- An ops engineer uses Cost Explorer to identify that a forgotten NAT Gateway is costing $120/month and deletes it immediately.
- A company buys a 1-year Compute Savings Plan after analysing 30 days of EC2 usage, reducing their baseline compute bill by 30%.
More examples
Set a monthly billing budget alert
Creates a monthly cost budget with an email alert at 80% of the $500 limit so you act before the cap is hit.
aws budgets create-budget \
--account-id 123456789012 \
--budget '{
"BudgetName": "monthly-limit",
"BudgetLimit": {"Amount": "500", "Unit": "USD"},
"TimeUnit": "MONTHLY",
"BudgetType": "COST"
}' \
--notifications-with-subscribers '[{
"Notification": {"NotificationType":"ACTUAL","ComparisonOperator":"GREATER_THAN","Threshold":80},
"Subscribers":[{"SubscriptionType":"EMAIL","Address":"[email protected]"}]
}]'Find top services by cost
Uses Cost Explorer to list the top AWS services by spend over the past 30 days to identify cost hot spots.
aws ce get-cost-and-usage \
--time-period Start=$(date -d '30 days ago' +%Y-%m-%d),End=$(date +%Y-%m-%d) \
--granularity MONTHLY \
--metrics BlendedCost \
--group-by Type=DIMENSION,Key=SERVICE \
--query 'ResultsByTime[0].Groups[*].[Keys[0],Metrics.BlendedCost.Amount]' \
--output tableTag resources for cost allocation
Tags a resource with project, environment, and team so cost explorer can break down the bill by these dimensions.
# Apply cost-allocation tags to an EC2 instance
aws ec2 create-tags \
--resources i-0abc12345 \
--tags \
Key=Project,Value=myapp \
Key=Environment,Value=prod \
Key=Team,Value=backend
Discussion