Skip to content

Instantly share code, notes, and snippets.

@Nxtra

Nxtra/template.yaml

Last active Nov 8, 2020
Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@Nxtra 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
You can’t perform that action at this time.