Sub topic 5
Budgets and alerts
This chapter assumes you can run AWS CLI commands, read JSON, and have seen spend in Cost Explorer (the previous chapters on cost visibility and tagging). You also need permission to use AWS Budgets.
What a budget does
A budget is a spending limit you define, paired with notifications. AWS Budgets compares your actual or forecasted spend with that limit and emails or messages people when a threshold is crossed. A budget does not stop spending by default. It only tells the owner.
A budget has three parts:
- Scope and type. The budget type is
COST,USAGE,RI_UTILIZATION, orSAVINGS_PLANS_COVERAGE, among others. This chapter usesCOST. - Limit and period. An amount, a unit such as USD, and a time unit such as
MONTHLY. - Notifications. A threshold, a comparison, and one or more subscribers.
Actual versus forecasted alerts
An ACTUAL notification fires after real spend crosses the threshold. A FORECASTED notification fires when AWS predicts you will cross it by the end of the period. Forecast alerts give you time to act, so use both.
Creating a budget from the CLI
Define the budget in budget.json. This one sets a 1000 USD monthly cost budget.
{
"BudgetName": "monthly-total",
"BudgetLimit": { "Amount": "1000", "Unit": "USD" },
"TimeUnit": "MONTHLY",
"BudgetType": "COST"
}Define the alert in notifications.json. It emails a subscriber when actual spend passes 80 percent of the budget.
[
{
"Notification": {
"NotificationType": "ACTUAL",
"ComparisonOperator": "GREATER_THAN",
"Threshold": 80,
"ThresholdType": "PERCENTAGE"
},
"Subscribers": [
{ "SubscriptionType": "EMAIL", "Address": "[email protected]" }
]
}
]Then create the budget. Replace the account ID with your own.
aws budgets create-budget \
--account-id 123456789012 \
--budget file://budget.json \
--notifications-with-subscribers file://notifications.jsonTo add a forecast alert, append a second object to the array with "NotificationType": "FORECASTED" and a threshold such as 100.
Choosing thresholds and owners
Pick thresholds that leave time to respond. A common pattern is an actual alert at 80 percent, a forecasted alert at 100 percent, and an actual alert at 100 percent.
Send alerts to the team that can change the spend, not only to finance. A budget scoped by a cost allocation tag, such as a team or product tag, makes the recipient the right person. This is where the tagging chapter pays off.
Common errors
| Problem | Cause | Fix |
|---|---|---|
| No alert arrives | Subscriber address is wrong or filtered as spam | Check the address and the spam folder |
| Budget scoped by tag shows zero | The tag is not activated as a cost allocation tag | Activate the tag in Billing, then wait for data |
| Forecast alert never fires | Too little spend history for a forecast | Rely on actual alerts for new accounts |
| Alert arrives too late | Billing data is delayed by up to a day | Set lower thresholds |
Exercise
Your team has a 2000 USD monthly budget. You want a warning before the month ends with an overspend, and another when real spend is close to the limit. Which two notifications would you add, and why?
Show answer
Add a FORECASTED notification at 100 percent, which warns you early that the month is on track to exceed the budget, and an ACTUAL notification at 80 percent (1600 USD), which warns you that real spend is approaching the limit. Forecasts give time to act, and actual alerts confirm the spend is real.
Exercise
A tag-scoped budget for the "checkout" team always shows 0 USD even though the team runs resources. What is the most likely cause?
Show answer
The tag has not been activated as a cost allocation tag in the Billing console, so spend is not attributed to it. Activate the tag and wait for billing data to update, which can take up to a day.