Cost Explorer tells you what you have spent when you ask. A budget tells you without being asked: it watches the month's spend and sends an alert when it passes a threshold.
A budget only alerts. Nothing is stopped or deleted; you read the email and decide.
Two files
The budget itself, in budget.json: a name, a limit, a period and what it counts.
{
"BudgetName": "market-monthly",
"BudgetLimit": { "Amount": "5", "Unit": "USD" },
"TimeUnit": "MONTHLY",
"BudgetType": "COST"
}The alert, in alert.json: when it fires and who hears about it.
[{
"Notification": { "NotificationType": "ACTUAL", "ComparisonOperator": "GREATER_THAN", "Threshold": 80, "ThresholdType": "PERCENTAGE" },
"Subscribers": [{ "SubscriptionType": "EMAIL", "Address": "ops@monstermarket.example" }]
}]ACTUAL means money already spent, and 80 with PERCENTAGE means 80 per cent of the limit: 4 USD.
Creating it
aws budgets create-budget --account-id 123456789012 --budget file://budget.json --notifications-with-subscribers file://alert.jsonThe Budgets API asks for the account on every call, so --account-id comes first: the twelve digits that aws sts get-caller-identity prints.
aws budgets describe-budget --account-id 123456789012 --budget-name market-monthlyThis reads the budget back, with the spend so far under CalculatedSpend. The alert is read separately:
aws budgets describe-notifications-for-budget --account-id 123456789012 --budget-name market-monthly