If there is one thing you don’t want to get from AWS, it’s a 14k bill. The internet is full of stories of people who have accidentally let their AWS usage get way out of hand – like Chris Short’s AWS bill heard around the world.
It usually happens one of two ways – someone gets hacked and the hacker uses AWS resources to mine cryptocurrency, or the account owner uses someone spins up an instance just forgets to turn it off. Leaving just one large instance like a
c5.12xlarge could end up costing you $1468 at the end of the month.
Nobody wants that.
The easiest way to not fall victim to this is using the AWS budgets system. Let’s explore how it works.
Setup a budget in AWS budgets
One of the easiest ways to avoid a surprise wallet assault is with AWS billing alerts. The process is painless.
Head over to the AWS billing service in the management UI (use the search bar) and click Budgets in the left sidebar.
Click the Create a budget button and you’ll see a screen with a bunch of budget options.
A Cost Budget is what most of us think of as a budget- you tell AWS how much money you want to spend and they alert you if you run over.
A Usage Budget is a little different, these are budgets based on resource usage instead of cost.
For example, you could setup a budget that alerts you if your EC2 instances have been running for over 100 hours in a month, or if you’ve transferred more than 10GB out of an S3 bucket in 30 days.
Add a name for your budget and set the period to monthly. You can use quarterly or annual budgets if they fit your needs, but be aware you might not get an alert until you’ve used 90% of your annual budget in just three weeks.
I’m not made of money, so I’m setting my monthly budget to $50.
The interface contains a bunch of options for filtering the budget results. You can filter the charges on your account based on several options including
- the service linked to the charges
- the account linked to the charges
- the usage type of the charges
- availability zone
If you wanted to set up a budget for your DevOps team’s usage of EC2 instances in
us-east-1 – you could do that. These options are very powerful.
Creating an overall budget alert
Having a budget is great, but what we really want is a notification when we hit the budget threshold. Actually, what would be even better is being notified before hitting the budget threshold. Fortunately, AWS has a Forecasted Cost option perfect for this.
Select the Forecasted Cost option and set your Alert threshold to 100% of your budget. This results in AWS sending you a notification anytime your expected usage crosses whatever budget threshold you set earlier. This is awesome because you’ll know about escalating costs before you’ve blown the budget, which is where most people go wrong.
Having a budget doesn’t help much if you don’t receive an alert before punching through it.
Next, add an email contact to notify if it generates an alert.
It’s also possible to tie these accounts into an SNS topic, but that’s a topic (see what I did there) for another time.
Finish up by clicking the Confirm Budget button. Congratulations, you’ve now got a budget notification setup to alert you if AWS thinks you’ll spend more than your budget in a month.
This budget should offer a lot of protection against unexpected AWS bills. Just remember to monitor your email and you’ll never get a surprise bill.
Creating individual budgets for EC2, S3, and Lambda
In addition to my overall budget, I’m going to configure some budgets that monitor my EC2 usage cost, S3 bucket cost, and Lambda cost. You could do this with any service, but these are three the services I rely on most heavily, so they make sense for me.
You should think about what services are your cost drivers and budget for them appropriately.
Generating weekly budget reports
Alerts are great for catching unexpected costs, but if you want to audit your account’s charges regularly, then budget reports are your best friend.
In the AWS billing console, click Budget Reports in the left-hand sidebar.
Click Create Budget Report and select the budgets you’ve created. I made four – overall, EC2, S3, and Lambda. I’m selecting them all so I get a weekly status update on each budget.
The next screen will ask you to configure delivery settings. I like weekly emails, so I chose a Weekly frequency with delivery on Monday.
On the next screen, click “Confirm budget report” and then click “Create”. You should now receive a weekly budget email showing you all the budgets you’ve created.