Inspecting AWS cost & budget state — cheaply
The rule
Do NOT use Cost Explorer to routinely check spend. The Cost Explorer API
is billed $0.01 per request, and so is every aws ce ... call and every
console "Cost and usage" / Cost Explorer widget load. On a tiny budget (e.g. a
$0.01 tripwire), the act of checking can be what trips it. Reach for the free
sources below first; use Cost Explorer only when itemized cost breakdowns are
genuinely required, deliberately, and tell the user it costs ~$0.01/request.
Free ways to inspect cost/budget (prefer these)
1. AWS Budgets API — free, and it's the number budget actions evaluate
# Recorded spend + forecast for one budget (ActualSpend is what actions check):
aws budgets describe-budget --account-id <ACCOUNT_ID> --budget-name <NAME> \
--query 'Budget.{limit:BudgetLimit.Amount,actual:CalculatedSpend.ActualSpend.Amount,forecast:CalculatedSpend.ForecastedSpend.Amount,updated:LastUpdatedTime}'
# All budgets in the account:
aws budgets describe-budgets --account-id <ACCOUNT_ID> \
--query 'Budgets[].{name:BudgetName,limit:BudgetLimit.Amount,actual:CalculatedSpend.ActualSpend.Amount}'
# Budget-action status / history (STANDBY | PENDING | EXECUTION_SUCCESS | ...):
aws budgets describe-budget-action --account-id <ACCOUNT_ID> --budget-name <NAME> --action-id <ID>
aws budgets describe-budget-actions-for-account --account-id <ACCOUNT_ID>
aws budgets describe-budget-action-histories --account-id <ACCOUNT_ID> --budget-name <NAME> --action-id <ID>
Note: CalculatedSpend lags — Budgets refreshes ~2–3×/day (8–12h apart), so it
can read $0.00 while the Bills page already shows a charge. That lag is normal.
2. CloudWatch billing metric — free (needs billing alerts enabled, us-east-1)
aws cloudwatch get-metric-statistics --namespace AWS/Billing \
--metric-name EstimatedCharges --dimensions Name=Currency,Value=USD \
--start-time <ISO> --end-time <ISO> --period 21600 --statistics Maximum \
--region us-east-1
3. Free Tier usage — free
aws freetier get-free-tier-usage --region us-east-1 # usage toward free-tier limits
4. Audit who queried costs (e.g. find who ran up Cost Explorer charges) — free
aws cloudtrail lookup-events \
--lookup-attributes AttributeKey=EventName,AttributeValue=GetCostAndUsage \
--start-time <ISO> --end-time <ISO> --region us-east-1
The userAgent distinguishes aws-cli/SDK calls (billed) from console/browser
(Mozilla/...) calls.
The paid Cost Explorer calls to avoid for routine checks
aws ce get-cost-and-usage, get-cost-and-usage-with-resources,
get-cost-forecast, get-dimension-values, get-cost-categories, etc. — each
~$0.01/request — and the Cost Explorer / "Cost and usage" console widgets.
When an itemized per-service or per-day breakdown is genuinely needed, Cost Explorer is the only source: do it in ONE deliberate paginated call and say it costs ~$0.01. Don't loop it or use it to poll.
Watching a budget/tripwire over time
Poll aws budgets describe-budget (free) — never Cost Explorer. Tell the user
the recorded spend lags real usage by 8–12h, so status changes appear on
Budgets' refresh cadence, not immediately.