0
0
AwsHow-ToBeginner · 4 min read

How to Set a Billing Alarm in AWS to Monitor Costs

To set a billing alarm in AWS, use AWS CloudWatch to create an alarm on the EstimatedCharges metric in the AWS/Billing namespace. Configure the alarm threshold and notification via an SNS topic to get alerts when your AWS costs exceed your set limit.
📐

Syntax

Creating a billing alarm involves these parts:

  • Namespace: Use AWS/Billing to access billing metrics.
  • MetricName: Use EstimatedCharges to track your AWS spending.
  • Threshold: The cost amount that triggers the alarm.
  • ComparisonOperator: Usually GreaterThanThreshold to alert when costs exceed the threshold.
  • EvaluationPeriods: Number of periods to evaluate before triggering.
  • AlarmActions: An SNS topic ARN to send notifications.
bash
aws cloudwatch put-metric-alarm \
  --alarm-name "BillingAlarm" \
  --namespace "AWS/Billing" \
  --metric-name "EstimatedCharges" \
  --dimensions Name=Currency,Value=USD \
  --statistic Maximum \
  --period 21600 \
  --evaluation-periods 1 \
  --threshold 100 \
  --comparison-operator GreaterThanThreshold \
  --alarm-actions arn:aws:sns:region:account-id:BillingAlerts \
  --unit None
💻

Example

This example creates a billing alarm that triggers when your AWS estimated charges exceed $50 USD. It sends a notification to an SNS topic named BillingAlerts.

bash
aws sns create-topic --name BillingAlerts

aws sns subscribe --topic-arn arn:aws:sns:us-east-1:123456789012:BillingAlerts --protocol email --notification-endpoint your-email@example.com

aws cloudwatch put-metric-alarm \
  --alarm-name "BillingAlarm50USD" \
  --namespace "AWS/Billing" \
  --metric-name "EstimatedCharges" \
  --dimensions Name=Currency,Value=USD \
  --statistic Maximum \
  --period 21600 \
  --evaluation-periods 1 \
  --threshold 50 \
  --comparison-operator GreaterThanThreshold \
  --alarm-actions arn:aws:sns:us-east-1:123456789012:BillingAlerts \
  --unit None
Output
TopicArn: arn:aws:sns:us-east-1:123456789012:BillingAlerts SubscriptionArn: pending confirmation Successfully put alarm 'BillingAlarm50USD'
⚠️

Common Pitfalls

  • Billing metrics are only available in the us-east-1 region. Make sure to run commands or create alarms in this region.
  • Billing data updates every 6 hours. The alarm period should be set accordingly (e.g., 21600 seconds).
  • Notifications require confirmed subscriptions. Confirm your email subscription to receive alerts.
  • Using wrong namespace or metric name. Always use AWS/Billing and EstimatedCharges.
bash
Wrong example:
aws cloudwatch put-metric-alarm \
  --alarm-name "WrongBillingAlarm" \
  --namespace "AWS/Usage" \
  --metric-name "Charges" \
  --threshold 50 \
  --comparison-operator GreaterThanThreshold

Right example:
aws cloudwatch put-metric-alarm \
  --alarm-name "CorrectBillingAlarm" \
  --namespace "AWS/Billing" \
  --metric-name "EstimatedCharges" \
  --threshold 50 \
  --comparison-operator GreaterThanThreshold
📊

Quick Reference

Remember these key points when setting a billing alarm:

  • Use AWS/Billing namespace and EstimatedCharges metric.
  • Set Currency dimension to your billing currency (e.g., USD).
  • Set period to 21600 seconds (6 hours) to match billing data update frequency.
  • Use an SNS topic for alarm notifications and confirm subscriptions.

Key Takeaways

Create billing alarms only in the us-east-1 region where billing metrics are available.
Use the AWS/Billing namespace and EstimatedCharges metric to track costs.
Set the alarm period to 21600 seconds to align with billing data updates every 6 hours.
Configure an SNS topic and confirm subscriptions to receive notifications.
Double-check metric names and namespaces to avoid configuration errors.