Billing alarms for your AWS account!

TL;DR Omg, stop wasting money without noticing it!

My sacred bill

You are a developer, a sandbox-player, a researcher, a poc-er, BUT not a cleaner..
You make beautiful sandbox projects, you are continuously exploring the limits of the cloud.
However, you forget to clean up unnecessary resources!
I am blaiming you, but actually it is me. And if you are here, maybe your are like me. emoji-smile

A solution

Billing alarms is what I need!
How do I configure them? How do I set them up?
There is a cloudformation template for that, right?!

Indeed, I went looking for a solution and found a repository by Dimitri Tarasowski.

You can use the following gist:

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
view raw template.yaml hosted with ❤ by GitHub

Or check out this repository: https://github.com/Nxtra/aws-billing-alarms.

Run the following command to deploy the stack. Don't forget to update your email and phone number.

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

Confirm the subscription via the email you've received.
And of you go, you will now get an sms and email when you go above your budget thresholds!

You can check the current status in cloudwatch too:


Be proactive and protect yourself against yourself. emoji-blush

Credits

Featured image by Pepi Stojanovski on Unsplash.