How to automate AWS Savings Plan Chargeback/Showback models using AWS Cost & Usage Report,Amazon Athena,AWS Eventbridge, Lambda & Simple Email Service
Automate AWS Savings Plan Chargeback/Showback models using AWS Cost & Usage Report in the most cost effective way!
Nithin Chandran R
Amazon Employee
Published Jun 11, 2024
Introduction:
Hey, AWS Users! Many AWS customers who use consolidated billing on AWS require the ability to allocate costs internally within the accounts in their AWS Organization.
⚡ Are you tired of manually calculating AWS savings plan chargeback/showback models? Let automation do the work for you! Learn how to use AWS Cost & Usage Report (CUR), Amazon Athena, AWS Cloudwatch, and AWS Simple Email Service to effortlessly manage your savings plans. 🧑🔧
What are AWS Savings Plans?
Before we dive deep, here's a quick primer on savings plans.
💰 Amazon Web Services introduced Savings Plans in November 2019. It is a flexible pricing model that allows customers to save up to 72% on Amazon Elastic Compute Cloud and AWS Fargate by committing to a consistent amount of compute usage (e.g. $10/hour) for either a 1 or 3 year term. The Cost and Usage Report contains the most comprehensive set of cost and usage data. It tracks your AWS spending and estimates charges associated with your account. Each report includes line items for each unique combination of AWS products, usage types, and operations that you use in your AWS account. For example, costs for RunInstances operations. In the AWS context, cost allocation refers to assigning or showing the costs of AWS resource usage back to the different cost centers, lines of business, departments, or products that consumed those resources.
Why Automation?
Automating AWS savings plan chargeback/showback models can save time and increase transparency by ensuring teams are aware of savings and can make informed decisions. Automated reports generated on a set schedule ensure accuracy and timeliness. Automation eliminates manual report generation and distribution freeing up time while providing increased visibility into cloud costs through regular reports enabling teams to track spend and identify optimization opportunities supporting the goal of cost management. In summary, automation supports objectives of accuracy, timeliness, visibility and cost optimization while reducing manual work.
Chargeback/Showback Logic selection :
Before you automate the chargeback or showback, you should review the logic you've selected for the activity. There are two types : Equittable Charge back and Non-Equittable chargeback.
- Equitable chargeback divides Savings Plan benefits evenly among cost centers, making it simple but inaccurate in reflecting actual usage. it is perceived as fairer but may subsidize high users.
- Non-equitable chargeback allocates benefits based on actual usage, more accurately reflecting true costs though complex to implement.The chargeback aligns costs with consumption but may seem unfair to low users.
Equitable chargeback is simpler while non-equitable is more accurate.
- The best approach depends on needs and priorities between simplicity and accuracy. In summary, the trade-off is between the simplicity of equitable chargeback and the accuracy of non-equitable chargeback.
- You can refer to this [AWS Blog : https://aws.amazon.com/blogs/aws-cloud-financial-management/how-to-build-a-chargeback-showback-model-for-savings-plans-using-the-cur/) for more context.
Solution in a nutshell :
The solution uses:
• Amazon S3 to store CUR data
• Amazon Athena for running SQL queries on the CUR data
• AWS Lambda to run the queries and generate reports
• Amazon SES to email the reports to stakeholders
• AWS CloudWatch Events to trigger the Lambda function on a schedule
Architecture Diagram:
Detailed Steps :
This solution is inspired from the well-architected framework lab outlined here by Na Zhang, Sr. Technical Account Manager-AWS. So, the following steps are to be followed till step 4 of creating lambda function.
After that, please follow the steps outlined here which is tailor made for Savings plan chargeback/Showback
Step 1 : Create S3 Bucket
Step 4 : Create a Lambda function
Step 5 : Customize SQL query strings
(i). In you local path where AutoCURDelivery.zip is located. Unzip and open config.yml in a text editor.
(ii). Find Body\_Text, insert a description of new query SavingsPlanChargeback
(iii). Find the section Query\_String\_List, add following new query string at the bottom of file (note the indent should be same as other query strings), save config.yml
(iii). Add config.yml back into AutoCURDelivery.zip , and upload zip file to S3.
(iv). Go to Lambda console, update function code path to above S3 path where new zip file is located, click Save. Perform [another Test](https://wellarchitectedlabs.com/Cost/300_Automated_CUR_Query_and_Email_Delivery/Images/execution_log.png) of the function.
(v). Check the cost & utilization report in the mail your recipient receives, there should be one more tab added in the excel file for Savings plan Chargeback along with the other default reports.
(**N.B :** You can delete the other reports and chose to only use this dedicated to Savings plan charge back as well)
**Step 5 : Create a Scheduled Amazon Eventbridge/Cloudwatch Event to trigger the AWS Lambda function periodically :**
1. Navigate to the Eventbridge dashboard and select Rules under the Events section.
2. Click on the Create rule button.
3. Select Rule type as **Schedule ,** Click on **Continue in Eventbridge Scheduler.**In the new window, select **Recurring Schedule** under **Schedule Pattern** and select **Cron-based schedule.** Verify the options as below and set the time using [cron expressions](https://docs.aws.amazon.com/scheduler/latest/UserGuide/schedule-types.html?icmpid=docs_console_unmapped#cron-based-syntax) :
4. Under Targets, click Add Target and select Lambda function from the drop-down menu. Pick the Auto\_CUR\_Delivery function and click on Configure details.
Select appropriate options and click next. Review all the steps and Click on Create Schedule.
Disabling the Scheduler :
To stop event triggering, choose the rule name that you created above from the Eventbridge scheduler, click **Actions** and select **Disable**.
Cost Estimation :
⚠︎ The cost varies based on the volume of data analyzed and the frequency of reporting. For small to medium-sized accounts, the estimated monthly expense is less than $5.00
Conclusion:
In this blog post, I showed you how to create AWS CUR, automate AWS Savings Plan Chargeback/Showback models using AWS Cost & Usage Report,Amazon Athena,AWS Eventbridge Scheduler, Lambda & Simple Email Service. You can see more details of cloud optimizaton, cost management in my Linked in Profile . Please let me know what you'd like to see and dive deep into my upcoming blogs! Until next time.
Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.