0
0
AwsHow-ToBeginner · 3 min read

How to Set Up AWS CloudWatch Alarm for Billing Alerts

To set up a CloudWatch alarm for billing, go to the AWS Billing console, enable billing alerts, then create a CloudWatch alarm on the EstimatedCharges metric. Set your threshold amount and notification options to get alerts when your AWS costs exceed that limit.
📐

Syntax

The main components to set up a billing alarm in CloudWatch are:

  • MetricName: Use EstimatedCharges to track your AWS costs.
  • Namespace: Use AWS/Billing which contains billing metrics.
  • Threshold: The cost amount that triggers the alarm.
  • ComparisonOperator: Usually GreaterThanOrEqualToThreshold to alert when costs exceed the threshold.
  • EvaluationPeriods: Number of periods to evaluate before triggering.
  • AlarmActions: The notification action, like sending an email via SNS.
bash
aws cloudwatch put-metric-alarm \
  --alarm-name "BillingAlarm" \
  --metric-name EstimatedCharges \
  --namespace AWS/Billing \
  --statistic Maximum \
  --period 21600 \
  --evaluation-periods 1 \
  --threshold 100 \
  --comparison-operator GreaterThanOrEqualToThreshold \
  --alarm-actions arn:aws:sns:us-east-1:account-id:topic-name \
  --dimensions Name=Currency,Value=USD
💻

Example

This example creates a CloudWatch alarm named BillingAlarm that triggers when your estimated AWS charges in USD reach or exceed $100. It sends a notification to an SNS topic to alert you.

bash
aws cloudwatch put-metric-alarm \
  --alarm-name "BillingAlarm" \
  --metric-name EstimatedCharges \
  --namespace AWS/Billing \
  --statistic Maximum \
  --period 21600 \
  --evaluation-periods 1 \
  --threshold 100 \
  --comparison-operator GreaterThanOrEqualToThreshold \
  --alarm-actions arn:aws:sns:us-east-1:123456789012:BillingAlerts \
  --dimensions Name=Currency,Value=USD
Output
An alarm named 'BillingAlarm' is created and will notify the SNS topic 'BillingAlerts' when estimated charges reach $100 or more.
⚠️

Common Pitfalls

  • Billing Alerts Not Enabled: You must enable billing alerts in your AWS account before CloudWatch billing metrics are available.
  • Wrong Region: Billing metrics are only available in the us-east-1 region, so run commands or create alarms there.
  • Incorrect Dimensions: Always specify Name=Currency,Value=USD to monitor charges in US dollars.
  • Missing SNS Subscription: Ensure your SNS topic has confirmed email subscriptions to receive notifications.
bash
aws cloudwatch put-metric-alarm \
  --alarm-name "BillingAlarm" \
  --metric-name EstimatedCharges \
  --namespace AWS/Billing \
  --statistic Maximum \
  --period 21600 \
  --evaluation-periods 1 \
  --threshold 100 \
  --comparison-operator GreaterThanOrEqualToThreshold \
  --alarm-actions arn:aws:sns:us-east-1:123456789012:BillingAlerts \
  --dimensions Name=Currency,Value=USD

# Wrong region 'us-west-2' used above. Correct region is 'us-east-1'.
📊

Quick Reference

  • Enable billing alerts in AWS Billing preferences.
  • Use us-east-1 region for billing metrics.
  • Set MetricName to EstimatedCharges and Namespace to AWS/Billing.
  • Specify Currency=USD dimension.
  • Use SNS to receive email notifications.

Key Takeaways

Enable billing alerts in AWS Billing console before creating alarms.
Billing metrics are only available in the us-east-1 region.
Use the EstimatedCharges metric with Currency=USD dimension for cost monitoring.
Set a threshold and connect an SNS topic to get notified.
Confirm SNS subscriptions to receive alarm notifications.