Sub topic 15
Acting on the numbers: Budgets and anomaly alerts
This chapter assumes you can already group Cost Explorer reports by an activated cost allocation tag, such as Project. Reports only show you spend when you open them. AWS Budgets and Cost Anomaly Detection watch the same data and notify you when something needs attention.
AWS Budgets
A budget compares your spend with a limit you set. It can track cost, usage, or Savings Plans and Reserved Instance coverage. A cost budget has four parts:
- A period: monthly, quarterly or yearly.
- An amount.
- Optional filters, such as service, linked account or tag.
- Notifications at thresholds you choose.
Each notification is either actual (spend has crossed the threshold) or forecasted (AWS predicts it will cross the threshold by the end of the period). Forecast alerts give you time to act, so use both.
A tag filter turns a budget into a per-project limit. The filter uses the form user:<TagKey>$<TagValue>, and the tag key must already be activated.
Save the budget definition as budget.json:
{
"BudgetName": "checkout-monthly",
"BudgetLimit": { "Amount": "1000", "Unit": "USD" },
"TimeUnit": "MONTHLY",
"BudgetType": "COST",
"CostFilters": { "TagKeyValue": ["user:Project$checkout"] }
}Save the alerts as notifications.json:
[
{
"Notification": {
"NotificationType": "FORECASTED",
"ComparisonOperator": "GREATER_THAN",
"Threshold": 100,
"ThresholdType": "PERCENTAGE"
},
"Subscribers": [
{ "SubscriptionType": "EMAIL", "Address": "[email protected]" }
]
},
{
"Notification": {
"NotificationType": "ACTUAL",
"ComparisonOperator": "GREATER_THAN",
"Threshold": 80,
"ThresholdType": "PERCENTAGE"
},
"Subscribers": [
{ "SubscriptionType": "EMAIL", "Address": "[email protected]" }
]
}
]Then create the budget:
aws budgets create-budget \
--account-id 111122223333 \
--budget file://budget.json \
--notifications-with-subscribers file://notifications.jsonReplace the account ID and email address with your own. The first alert fires when forecast spend exceeds 100% of the limit. The second fires when actual spend passes 80%.
Cost Anomaly Detection
A budget needs you to know the right number in advance. Cost Anomaly Detection does not. It learns your normal spending pattern with machine learning and flags unusual spikes. Detection runs on a monitor, which can cover:
- All AWS services.
- A linked account.
- A cost category.
- A cost allocation tag.
A tag monitor is useful when you have many teams. A spike in one project's spend is flagged even if the account total barely moves.
You attach an alert subscription to a monitor. It sets who is notified (email or an SNS topic), how often, and a minimum impact threshold in dollars or percent. Set the threshold high enough to skip small fluctuations. If it is too low, people begin to ignore the alerts.
Choosing between them
| Question | Use |
|---|---|
| Will this project stay under its agreed limit? | Budget with a tag filter |
| Did something unexpected just change? | Anomaly monitor |
| Who owns the spend that triggered the alert? | Cost Explorer, grouped by tag |
Alerts are only as precise as your tagging. Untagged spend falls outside every tag-filtered budget and tag monitor, so keep reducing it.
Exercise
Why might a budget filtered on user:Project$checkout report $0 even though checkout resources are running?
Show answer
The Project tag key may not be activated as a cost allocation tag. It may also have been activated recently, so earlier spend is not yet attributed to it. The resources themselves could also lack the tag. Check with aws ce list-cost-allocation-tags --status Active, then confirm the tag on the resources.