0
0
AWScloud~5 mins

Budgets and cost anomaly detection in AWS - Commands & Configuration

Choose your learning style9 modes available
Introduction
Managing cloud costs can be tricky because expenses can grow unexpectedly. Budgets help you set spending limits, and cost anomaly detection alerts you when costs change in unusual ways. This helps you avoid surprises and control your cloud spending.
When you want to set a monthly spending limit for your cloud resources to avoid overspending.
When you need alerts if your cloud costs suddenly increase due to unexpected usage.
When you want to track your cloud spending against a planned budget for a project.
When you want to find unusual cost patterns that might indicate errors or security issues.
When you want to receive notifications before your cloud costs exceed a certain threshold.
Commands
This command creates a monthly budget named 'MyMonthlyBudget' with a limit of 100 USD for the AWS account. It helps you track and control your monthly cloud spending.
Terminal
aws budgets create-budget --account-id 123456789012 --budget '{"BudgetName":"MyMonthlyBudget","BudgetLimit":{"Amount":"100","Unit":"USD"},"TimeUnit":"MONTHLY","BudgetType":"COST","CostFilters":{},"CostTypes":{"IncludeTax":true,"IncludeSubscription":true,"UseBlended":false},"TimePeriod":{"Start":"2024-06-01T00:00:00Z"}}'
Expected OutputExpected
{"Budget":{"BudgetName":"MyMonthlyBudget","BudgetLimit":{"Amount":"100","Unit":"USD"},"TimeUnit":"MONTHLY","BudgetType":"COST","CostFilters":{},"CostTypes":{"IncludeTax":true,"IncludeSubscription":true,"UseBlended":false},"TimePeriod":{"Start":"2024-06-01T00:00:00Z"}}}
--budget - Defines the budget details in JSON format
--account-id - Specifies the AWS account ID where the budget is created
This command lists all budgets for the specified AWS account so you can verify your budget was created correctly.
Terminal
aws budgets describe-budgets --account-id 123456789012
Expected OutputExpected
{"Budgets":[{"BudgetName":"MyMonthlyBudget","BudgetLimit":{"Amount":"100","Unit":"USD"},"TimeUnit":"MONTHLY","BudgetType":"COST"}]}
--account-id - Specifies the AWS account ID to list budgets for
This command lists your current cost anomaly detection subscriptions, which define who gets alerts when unusual cost changes happen.
Terminal
aws ce get-anomaly-subscriptions
Expected OutputExpected
{"AnomalySubscriptions":[]}
This command creates a cost anomaly detection subscription named 'MyCostAlerts' that sends daily email alerts to alerts@example.com when anomalies are detected.
Terminal
aws ce create-anomaly-subscription --subscription '{"SubscriptionName":"MyCostAlerts","Frequency":"DAILY","Subscribers":[{"Type":"EMAIL","Address":"alerts@example.com"}],"MonitorArnList":["arn:aws:ce::123456789012:anomalymonitor/abcdef12-3456-7890-abcd-ef1234567890"]}'
Expected OutputExpected
{"Subscription":{"SubscriptionName":"MyCostAlerts","Frequency":"DAILY","Subscribers":[{"Type":"EMAIL","Address":"alerts@example.com"}],"MonitorArnList":["arn:aws:ce::123456789012:anomalymonitor/abcdef12-3456-7890-abcd-ef1234567890"]}}
--subscription - Defines the anomaly subscription details in JSON format
This command lists all anomaly monitors in your account, which watch for unusual cost patterns.
Terminal
aws ce list-anomaly-monitors
Expected OutputExpected
{"AnomalyMonitors":[{"MonitorArn":"arn:aws:ce::123456789012:anomalymonitor/abcdef12-3456-7890-abcd-ef1234567890","MonitorName":"DefaultMonitor"}]}
Key Concept

If you remember nothing else from this pattern, remember: setting budgets and enabling cost anomaly detection helps you catch unexpected cloud costs early and stay in control.

Common Mistakes
Not specifying the correct AWS account ID when creating or listing budgets.
The commands will fail or show no results because budgets are account-specific.
Always include the correct --account-id flag with your AWS account number.
Creating anomaly subscriptions without linking to a valid anomaly monitor ARN.
Without a monitor ARN, the subscription cannot track anomalies and will not send alerts.
First list or create anomaly monitors and use their ARNs when creating subscriptions.
Ignoring the budget time period start date or setting it incorrectly.
Budgets won't track costs properly if the time period is wrong or missing.
Set the TimePeriod Start date to the current or future date in ISO 8601 format.
Summary
Create a budget with aws budgets create-budget to set spending limits.
Verify budgets with aws budgets describe-budgets to check your settings.
Use aws ce list-anomaly-monitors and aws ce create-anomaly-subscription to set up cost anomaly detection alerts.
These tools help you monitor and control unexpected cloud cost changes.