Controlling Projected User Costs Through Monthly Budget Policies
With the announcement of our new AWS Price List Query APIs, let’s discuss a use-case that you can deploy directly to your AWS account. Customers often ask for ways to proactively control costs while having the flexibility to experiment with different AWS resource sizes and types. The solution we’ll discuss in this blog post gives you the ability to project monthly Amazon EC2 costs for individual Identity and Access Management (IAM) users and receive alerts when user projected costs exceed their configured thresholds. You can deploy this solution to your AWS account using AWS CloudFormation below.
When a user launches or starts EC2 instances, the solution calculates the projected monthly cost using the Price List Query API, and aggregates those costs for each AWS user. Likewise, when a user stops or terminates instances, the user’s projected cost is reduced. The solution also allows user budget targets to be set, which gives Operational Management the ability to intervene when projected thresholds are exceeded before the actual monthly costs are accrued.
- When a user launches an EC2 instance, user and launch details are logged in AWS CloudTrail, which triggers an Amazon CloudWatch event.
- The CloudWatch event triggers a Lambda function, which performs three tasks:
- Calls the AWS Price List Query API to retrieve the price of EC2 instance on which action was taken.
- Based on event type (Launch/Start or Stop/Terminate), edits the DynamoDB table with new price based upon the continued projection for the month.
- Sends a trigger to another Lambda function which will check for a policy breach.
- The policy breach Lambda function checks if the user in the DynamoDB table has breached the budgeted threshold
- If the budget threshold is breached, the Lambda function generates an Amazon SNS notification to email alert the IT operations team.
Here is an example of the notification email sent to stakeholders:
The AWS Price List API makes this process easy to obtain accurate EC2 price information.
The following CloudFormation templates below can be deployed in your environment with CloudTrail enabled by simply filling in a few parameters:
|N. Virginia (us-east-1)|
|Asia Pacific – Mumbai (ap-south-1)|
|Asia Pacific – Sydney (ap-southeast-2)|
|Asia Pacific – Tokyo (ap-northeast-1)|
|EU – Ireland (eu-west-1)|
|EU – London (eu-west-2)|
- This solution should be used as an addition to the AWS Billing and Cost Management tools. The solution calculations are based upon on-demand EC2 costs per second for non-Windows operating systems and per hour for Windows operating systems. They don’t include instances with pre-installed software or AWS Marketplace software licenses.
- The monthly cost of the AWS resources to deploy this cost-control solution is in most scenarios, < $5.
- These projections are only estimates, and monthly charges will be based on your actual usage of AWS services, and may vary from the projections provided.
As organizations are given freedoms to experiment with computing resources in the AWS cloud, they often need governance controls for an effective solution. The AWS Management Tools and partner ecosystem enable you to deploy or even build the right governance solution for your organization’s needs.
About the Author:
|Adam Westrich is a Solutions Architect based in Southern California. He is passionate about working with customers on their AWS Cloud journey, especially leveraging AWS managed services, including serverless technologies.|
Thank you to Shashi Prabhakar for his contributions to this post.