TLDR

  • By spending a few minutes of your time now, you can prevent a billing catastrophe in the future!
  • There’s a lot of flexibility in what you can alert on and how that lets you fit it to your needs.

Why Use AWS Budgets?

A few days ago, I was speaking with a colleague who was toying with AWS Textract and was surprised when he had gotten contacted by an AWS rep trying to sell him business-tier support a few days later. When he logged in to his account, he saw that he managed to accumulate a $16,000 AWS bill due to an oversight in how he set up his code. Instead of testing Textract against a few documents, he tried it against thousands, each with a hundred pages. This got me thinking about a post I had written not too long ago that centered around keeping up with technology trends and how not doing so caused a massive spike in KMS costs.

Both of these costly mistakes could have been prevented with an easy setup of the AWS Budgets service.


Creating a Budget

Creating a basic budget is pretty straightforward. There’s a workflow that can be followed in the AWS console. There are different options for types of budgets, but the primary one is the Cost Budget. That’s not to say the others aren’t useful, but the cost budget lets you convert usage into actual spend and notify on what’s important: “How much of your money are you spending?”

While not reporting and alerting on usage, the cost budget has more options to filter and set the budget scope on than the usage budget, which is an interesting choice by the AWS team. The cost budget scope contains many of the same dimensions in the Cost Explorer.

After selecting the cost budget, you’re presented with a simple web form asking for the budget name, amount, and scope. Putting name aside, let’s talk about the Budget Amount panel.

The Budget Amount panel

This panel has a few settings. None are overly complex, but I’ll briefly go into each one.

The period selection is pretty simple: How often do you want the budget to reset? You can select daily, monthly, quarterly, or annually. I’ve found monthly to be a good sweet spot, but daily spending is suitable for personal accounts. Quarterly and annually are likely ones you may encounter for enterprise or financial planning budgets.

The renewal type is also straightforward. Do you want the budget to recur or expire at some time in the future? Then you’ll select the start (and end if you pick an expiring budget) dates.

Budgeting method is the most complex option on this part of the form. Fixed is the easiest. Set a fixed amount for the budget period that was selected above. Planned will let you set a value for each month or autogenerate it based on percentage growth. Auto-adjusting is a newer option that leverages forecasted values or historical data to generate your budget value. It’s an interesting approach for those who want to remove any budget maintenance that may come from growth or optimization occurring monthly.

The Budget Amount panel

Budget Scope selection

Next is the scope selection. Simple on the surface, but it contains a lot of potential for a very detailed selection of filters. This is also where you can exclude certain types of charges, such as credits, taxes, support, etc. If you need a simple, account-wide budget, then this is fine to leave alone, but what if you wanted to set up a budget to monitor your EC2 spot usage or your data transfer costs out of Lambda for US-West-2 and US-East-2? Well, you can!

A simple filter for EC2 Spot budgets
A budget scope looking at data transfer out for lambda in specific regions

Configuring Alerts

What good are these budgets if they don’t notify anyone when triggered? You can create numerous alerts on both forecasted and actual values. You can send an email, SNS, or AWS Chatbot alerts. I’d recommend setting up one for actual values and one for forecasted values. AWS cost forecasting isn’t always the most accurate, but it can be an additional layer of detection against things going awry in your account.

The alerts panel.

Configuring Actions

Budget actions are fascinating; from one perspective, it’s incredibly interesting that based on alerts configured in the previous step, you can apply a Service Control Policy (SCP) or even shut down RDS or EC2 instances. However, it’s also very limited. You need to select the instance ids when wanting to shutdown EC2 instances; this doesn’t work if you have a dynamic environment with instances being terminated and recreated. The actions also don’t allow for anything more complex than that. If, for example, you could trigger a lambda or step function for a Budget alert being triggered, you would be able to take many different types of actions.


Scaling Budget Creation (Using Terraform)

If you only have one account, you may only need one budget. However, that’s not always the case. Budget creation and management are fully compatible with Terraform. In fact, for some, it may be simpler to understand and put together budgets in Terraform than through the Console wizard.

Terraform has two related resources: aws_budgets_budget (Doc Link) and aws_budgets_budget_action (Doc Link). Below is a brief example similar to the example built in the GUI above.

resource "aws_budgets_budget" "account" {
  name              = "AccountWide"
  budget_type       = "COST"
  limit_amount      = "5000"
  limit_unit        = "USD"
  time_unit         = "MONTHLY"

  notification {
    comparison_operator        = "GREATER_THAN"
    threshold                  = 95
    threshold_type             = "PERCENTAGE"
    notification_type          = "ACTUAL"
    subscriber_email_addresses = ["me@carlo.cloud"]
  }

  notification {
    comparison_operator        = "GREATER_THAN"
    threshold                  = 110
    threshold_type             = "PERCENTAGE"
    notification_type          = "FORECASTED"
    subscriber_email_addresses = ["me@carlo.cloud"]
  }
}

Wrapping Up

That’s all there is to it; this is a simple but often overlooked service in AWS. It can give some peace of mind, so you never need to receive that call from finance or AWS asking if you want to buy business-level support due to your prolific usage of a service you never intended to use.


References