Skip to content

Instantly share code, notes, and snippets.

@Nxtra
Last active November 8, 2020 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nxtra/6629097f7ab7dd99bf01bb7b4f06e60e to your computer and use it in GitHub Desktop.
Save Nxtra/6629097f7ab7dd99bf01bb7b4f06e60e to your computer and use it in GitHub Desktop.
Setup a billing alarm for your AWS account with cloudformation
AWSTemplateFormatVersion: "2010-09-09"
Description: Billing Alerts for your AWS Account
Parameters:
Email:
Type: String
Default: youremail@somerandomdomain.com
Description: The email address to receive alerts per email
Phone:
Type: String
Default: "+3212312828345"
Description: The mobile phone number to receive SMS message alerts
Mappings:
EstimatedCharges:
AlarmRange:
"Threshold": 10 # Triggers an alarm if charges go above $10
Resources:
BillingAlert:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmActions:
- !Ref BillingAlertTopic
AlarmDescription:
!Join [
"",
[Alert for $, !FindInMap [EstimatedCharges, AlarmRange, Threshold]],
]
ComparisonOperator: GreaterThanThreshold
Dimensions:
- Name: Currency
Value: USD
EvaluationPeriods: 1
MetricName: EstimatedCharges
Namespace: AWS/Billing
Period: 21600
TreatMissingData: ignore
Statistic: Maximum
Threshold: !FindInMap [EstimatedCharges, AlarmRange, One]
BillingAlertTopic:
Type: AWS::SNS::Topic
AlarmSubscriberEmail:
Type: AWS::SNS::Subscription
Properties:
Endpoint: !Ref Email
Protocol: email
TopicArn: !Ref BillingAlertTopic
AlarmSubscriberSMS:
Type: AWS::SNS::Subscription
Properties:
Endpoint: !Ref Phone
Protocol: sms
TopicArn: !Ref BillingAlertTopic
@Nxtra
Copy link
Author

Nxtra commented Nov 8, 2020

Deploy using the following command:

 aws cloudformation deploy --template template.yaml --stack-name billing-alerts --capabilities CAPABILITY_IAM --region us-east-1 --parameter-overrides Email=YOUR_EMAIL Phone=YOUR_PHONE_NUMBER

Based on: https://github.com/tarasowski/aws-billing-alarm-cloudformation-template. Extended by: https://github.com/Nxtra/aws-billing-alarms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment