DEV Community

Cover image for Budget Controls for AWS: Automatically Manage Your Cloud Costs
Nam La
Nam La

Posted on

Budget Controls for AWS: Automatically Manage Your Cloud Costs

If you are new to AWS, you may be wondering how you can learn and experiment with cloud services while keeping your spend under your control. Budget Controls for AWS is an open-source solution designed to solve this problem. This solution was designed for customers new to AWS with no prior experience. It automatically watches your spending and takes actions you define when costs reach certain thresholds.

The solution uses a custom tag named BudgetControlAction which is automatically applied to supported resources. The allowed case-sensitive values for this tag are Inform, Stop, and Terminate.

  1. The default value is Inform. When the budget is consumed and the actions are triggered, with this value set, the account owner is simply reminded that this resource is in use, and no further action is taken.

  2. The next allowed value is Stop. If this value is set by the account owner, when the actions are triggered, this will stop the resource. The resource will no longer generate charges, and can be restarted whenever the account owner wishes. Note, any service dependencies, such as storage attached to compute instances, will continue to generate charges.

  3. The last allowed value is Terminate, which is destructive. When the actions are triggered, resources with this tag value will be permanently deleted. This value should be used for test or development resources that can be easily recreated later. As a reminder, this action is permanent, and not reversible.

The Budget Controls for AWS solution can be found on Github at https://github.com/awslabs/budget-controls-for-aws.

Deploying the solution

Step 1: Create Stack in CloudFormation
The file named budgetcontrol_resources.yaml is an AWS CloudFormation template that you will use to deploy the solution.
Note: The Budget Controls for AWS solution runs in a single region.

Click Next, and you will be taken to the Specify stack details page. Supply the required parameters for the stack. Pay attention to spending values ​​and email feedback information.

Step 2: Managing the tag values
Entering a new value for the tag. I use the "Stop" value so that when the spending threshold is reached the tagged resource will stop.

Check if resource is tagged or not? Here I have tagged a running ec2 instance.

Actions taken once budget is spent

  • When your budget is 80% consumed, an email will be sent. No further actions will be taken.
  • When your budget is 90% consumed, AWS Budgets will send a message to an SNS topic, which causes the workflow to execute.
  • By default the workflow is triggered at 90% of the budget. You may change this default behavior to trigger at 100% by manually editing the budget in the Billing and Cost Management console, under Budgets.
  • After the workflow has executed, the resources can be restarted or rebuilt as desired. Unless the budget is changed to a higher amount, it will only trigger the workflow at most once each month. When the budget is reset on the first day of the next month, it will not change the state of any resources.

Note: OpenSearch clusters cannot be stopped; they can only be deleted. Therefore, "Terminate" is the only tag value that will result in a destructive action for OpenSearch clusters. Values of "Inform" and "Stop" will simply report that the resource is in use.

Thank you!

Top comments (0)