0
0
AWScloud~7 mins

Setting up billing alerts in AWS - Step-by-Step CLI Walkthrough

Choose your learning style9 modes available
Introduction
Sometimes your cloud costs can grow unexpectedly. Setting up billing alerts helps you get notified when your spending reaches certain limits so you can avoid surprises.
When you want to be notified if your monthly AWS bill exceeds a certain amount.
When you manage multiple AWS accounts and want to track spending per account.
When you want to control costs by receiving alerts before charges get too high.
When you want to automate cost monitoring without checking the AWS console daily.
When you want to receive email notifications about your AWS billing status.
Commands
This command creates a budget in AWS using the details defined in the budget.json file. It sets the spending limit and alert thresholds.
Terminal
aws budgets create-budget --account-id 123456789012 --budget file://budget.json
Expected OutputExpected
{"Budget":{"BudgetName":"MyMonthlyBudget","BudgetLimit":{"Amount":"100","Unit":"USD"},"TimeUnit":"MONTHLY","BudgetType":"COST"},"ResponseMetadata":{"RequestId":"abcd1234-5678-90ef-ghij-klmnopqrstuv","HTTPStatusCode":200}}
--account-id - Specifies the AWS account ID where the budget is created
--budget - Points to the JSON file that defines the budget details
Creates an SNS topic named BillingAlerts to send notifications when budget thresholds are reached.
Terminal
aws sns create-topic --name BillingAlerts
Expected OutputExpected
{"TopicArn":"arn:aws:sns:us-east-1:123456789012:BillingAlerts"}
--name - Sets the name of the SNS topic
Subscribes your email to the SNS topic so you receive alert emails when the budget threshold is crossed.
Terminal
aws sns subscribe --topic-arn arn:aws:sns:us-east-1:123456789012:BillingAlerts --protocol email --notification-endpoint user@example.com
Expected OutputExpected
{"SubscriptionArn":"pending confirmation"}
--topic-arn - Specifies the SNS topic to subscribe to
--protocol - Defines the communication method, here email
--notification-endpoint - The email address to receive notifications
Links the budget with the notification and subscribers so alerts are sent when spending reaches the set limit.
Terminal
aws budgets create-notification --account-id 123456789012 --budget-name MyMonthlyBudget --notification file://notification.json --subscribers file://subscribers.json
Expected OutputExpected
{"ResponseMetadata":{"RequestId":"efgh5678-1234-90ab-cdef-ghijklmnopqr","HTTPStatusCode":200}}
--account-id - AWS account ID where the budget exists
--budget-name - Name of the budget to attach the notification
--notification - JSON file defining the alert threshold and type
--subscribers - JSON file listing who receives the alert
Key Concept

If you remember nothing else from this pattern, remember: setting a budget with notifications and subscribing an email lets you get cost alerts automatically.

Common Mistakes
Not confirming the email subscription to the SNS topic
Without confirmation, you won't receive any alert emails.
Check your email inbox and click the confirmation link to activate the subscription.
Using incorrect JSON format in budget or notification files
AWS commands will fail or create invalid budgets without proper JSON structure.
Validate JSON files with a linter before running commands.
Not specifying the correct AWS account ID
Budgets and notifications won't be created in the intended account.
Double-check the account ID matches your AWS environment.
Summary
Create a budget with a spending limit using a JSON file and AWS CLI.
Create an SNS topic and subscribe your email to receive alerts.
Link the budget with notifications and subscribers to trigger alerts automatically.