Automating Aws Cost Optimization Using Iac(Terraform)

This project focuses on cost optimization while also improving resource management, monitoring, and cost analysis. It’s a comprehensive approach to managing cloud resources efficiently and cost-effectively.
Incorporating these strategies can make a sig…


This content originally appeared on DEV Community and was authored by Louretta

This project focuses on cost optimization while also improving resource management, monitoring, and cost analysis. It’s a comprehensive approach to managing cloud resources efficiently and cost-effectively.
Incorporating these strategies can make a significant difference for small businesses, helping them thrive in a competitive landscape while maintaining financial health and operational efficiency.
Resources used for this project includes: AWS Resource Groups,
Amazon CloudWatch Dashboards, Amazon CloudWatch Alarms, AWS Budgets with email/SNS alerts, Cost and Usage Report (CUR),Aws Lambda ,S3 Bucket for CUR storage and Amazon QuickSight for visualization
*Architectural View *
Image description
***PEREQUISITES *
Basic Knowledge of AWS Services
AWS Management Console
Scripting and Automation
Understanding of Cost Management Tools

Terraform setup
Terraform was used to ensure consistency and repeatability in resource provisioning and also automating infrastructure deployment reduces errors , manual effort and Tracks infrastructure changes using version control.

Image description

Add resource groups for cost monitoring, budgets and cost and usage report: This Provides detailed billing and usage data for all AWS services

Image description

Add S3 bucket resource group: This stores Cost and Usage Reports (CUR) data in a specified folder structure. , s3 is cost effective and acts as a data source for QuickSight

Image description

Add resource groups for cloud watch dashboard alarms and Lambda archive_file: This Monitors cost-related metrics like Estimated Charges and triggers alerts for anomalies to SNS when threshold set is exceeded
Terraform archive_file was used to automate the ZIP process eliminating the need for external dependencies.

Image description
Add a python script for your Lambda function. This Automate Resource Scheduling using Lambda-based start/stop automation

Image description

Configure your Lambda function to trigger start/stop resources based on a schedules via Event Bridge (make reference to the script above)
and for best security practices, add Iam role for Lambda. This Securely grants permissions to CUR, QuickSight, Lambda, and other services.
Image description

Add Lambda Iam policy-This ensure resources only have the permissions they need and provides fine-grained control for secure infrastructure operations

Image description
run terraform init, plan and apply to deploy
Image description

Some Tips :you can use commands to output the result on console should look like this.

Image description

some of the outs via console

Image description

Always remember to clean after yourself -Run terraform destroy to clean resources
PS: S3 bucket has to be emptied before it can be deleted, best to do the console

Image description
Feel free to pull codes from my GitHub. Happy Coding
https://github.com/Louretta/Aws-cost-optimization-Automation.git


This content originally appeared on DEV Community and was authored by Louretta


Print Share Comment Cite Upload Translate Updates
APA

Louretta | Sciencx (2025-01-11T01:17:35+00:00) Automating Aws Cost Optimization Using Iac(Terraform). Retrieved from https://www.scien.cx/2025/01/11/automating-aws-cost-optimization-using-iacterraform-2/

MLA
" » Automating Aws Cost Optimization Using Iac(Terraform)." Louretta | Sciencx - Saturday January 11, 2025, https://www.scien.cx/2025/01/11/automating-aws-cost-optimization-using-iacterraform-2/
HARVARD
Louretta | Sciencx Saturday January 11, 2025 » Automating Aws Cost Optimization Using Iac(Terraform)., viewed ,<https://www.scien.cx/2025/01/11/automating-aws-cost-optimization-using-iacterraform-2/>
VANCOUVER
Louretta | Sciencx - » Automating Aws Cost Optimization Using Iac(Terraform). [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/01/11/automating-aws-cost-optimization-using-iacterraform-2/
CHICAGO
" » Automating Aws Cost Optimization Using Iac(Terraform)." Louretta | Sciencx - Accessed . https://www.scien.cx/2025/01/11/automating-aws-cost-optimization-using-iacterraform-2/
IEEE
" » Automating Aws Cost Optimization Using Iac(Terraform)." Louretta | Sciencx [Online]. Available: https://www.scien.cx/2025/01/11/automating-aws-cost-optimization-using-iacterraform-2/. [Accessed: ]
rf:citation
» Automating Aws Cost Optimization Using Iac(Terraform) | Louretta | Sciencx | https://www.scien.cx/2025/01/11/automating-aws-cost-optimization-using-iacterraform-2/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.