AWS Fundamentals: Setting Up Budget Alarms for Cost Monitoring

Listen to this Post

Please remember to set up at least one budget alarm for your AWS account. It’s easy to overlook resources like EC2 instances used for testing that you forgot to terminate. All non-serverless, pay-as-you-go services can rapidly accumulate costs! If you’re using AWS Organizations and consolidated billing, you’ll create the billing alarms on your root account, which will include the costs for the entire organization. You won’t need to worry about adding new accounts; they’ll be automatically included in the cost monitoring.

Practice Verified Codes and Commands

1. Create a Budget Alarm using AWS CLI:

aws budgets create-budget \
--account-id 123456789012 \
--budget file://budget.json \
--notifications-with-subscribers file://notifications.json

Example `budget.json`:

{
"BudgetName": "MonthlyBudget",
"BudgetLimit": {
"Amount": "100",
"Unit": "USD"
},
"TimePeriod": {
"Start": "2023-10-01",
"End": "2023-10-31"
},
"TimeUnit": "MONTHLY",
"BudgetType": "COST"
}

Example `notifications.json`:

{
"Notification": {
"NotificationType": "ACTUAL",
"ComparisonOperator": "GREATER_THAN",
"Threshold": 80,
"ThresholdType": "PERCENTAGE"
},
"Subscribers": [
{
"SubscriptionType": "EMAIL",
"Address": "[email protected]"
}
]
}

2. Check Budget Alarms using AWS CLI:

aws budgets describe-budgets --account-id 123456789012

3. Terminate Unused EC2 Instances:

aws ec2 terminate-instances --instance-ids i-0abcd1234efgh5678

4. List Running EC2 Instances:

aws ec2 describe-instances --filters "Name=instance-state-name,Values=running"

5. Enable AWS Cost Explorer:

aws ce get-cost-and-usage \
--time-period Start=2023-10-01,End=2023-10-31 \
--granularity MONTHLY \
--metrics "UnblendedCost"

What Undercode Say

Setting up budget alarms in AWS is a critical step in managing cloud costs effectively. By using AWS CLI commands, you can automate the creation of budget alarms, monitor your spending, and terminate unused resources to avoid unnecessary charges. The `aws budgets create-budget` command allows you to define a budget and set up notifications when your spending exceeds a certain threshold. This is particularly useful for organizations using AWS Organizations, as the root account can monitor costs across all linked accounts. Additionally, regularly checking for running EC2 instances with `aws ec2 describe-instances` and terminating unused ones with `aws ec2 terminate-instances` can help keep costs under control. AWS Cost Explorer, enabled via aws ce get-cost-and-usage, provides detailed insights into your spending patterns, helping you make informed decisions. By integrating these practices into your workflow, you can ensure that your AWS usage remains cost-efficient and aligned with your financial goals. For more advanced cost management strategies, consider exploring AWS Cost Anomaly Detection and AWS Budgets API for programmatic control. Always remember to review your AWS billing dashboard regularly and adjust your budgets as needed to reflect changes in your usage patterns.

References:

initially reported by: https://www.linkedin.com/posts/aws-fundamentals_please-remember-to-set-up-at-least-one-budget-activity-7302658077948825600-Xs4s – Hackers Feeds
Extra Hub:
Undercode AIFeatured Image