
Unleashing Cloud Savings: Turbo-charge Your AWS Cost Optimization with EBS Snapshot Management!
AWS Infrastructure Diagram
Introduction:
Are you ready to uncover hidden savings in your AWS cloud infrastructure? In this engaging blog post, we’ll embark on an exciting journey toward optimizing your AWS costs by efficiently managing EBS snapshots. Say goodbye to unnecessary expenses and hello to a leaner, more cost-effective cloud setup!
Prerequisites:
- Basic understanding of AWS services, specifically EC2 instances and EBS volumes.
- An AWS account with sufficient permissions to manage EBS snapshots and EC2 instances.
- Familiarity with Python programming.
Objective:
Our mission is simple: to develop a powerful yet user-friendly solution to automate the identification and deletion of unused EBS snapshots. By the end of this blog, you’ll have two stellar approaches in your arsenal — Terraform for those who love shortcuts and a thrilling manual approach for the brave-hearted.
Terraform Approach — Quick & Painless:
Ready to kickstart your cost optimization journey without breaking a sweat? We’ve got you covered! Just follow the link to our GitHub repository containing Terraform magic. With a few clicks, you’ll unleash the potential of a serverless AWS Lambda function. Watch as it dances its way through unnecessary EBS snapshots — leaving you with a lean, cost-optimized environment!
Terraform Code: https://github.com/AmanPathak-DevOps/Terraform-for-AWS/tree/master/Non-Modularized/EBS-Snapshot-Cost-Optimization
Manual Approach — Adventure into the Code:
For the daredevils who seek a deeper understanding, we’ve prepared an action-packed manual approach! Dive into the exhilarating world of Python and the Boto3 library as we create a powerful AWS Lambda function. Be the hero who fetches snapshots, battles unused resources, and emerges victorious by slashing storage costs!
Step-by-Step Implementation Guide:
Hold on tight as we embark on an epic step-by-step journey! Witness the magic of Python code, the thrill of EC2 instance status checks, and the triumph of deleting unwanted EBS snapshots. We’ll guide you through each twist and turn, ensuring you grasp the essence of cost optimization.
Click on Launch Instances to create an EC2 instance.
Just give the instance name and the rest of the things keep as it is.
Now, you can see the volumeID that is attached to the instance.
Create a Snapshot of the volume which is attached to the instance.
Select VolumeID that is attached to the instance.
You can see here, the snapshot has been created.
Create a lambda function which will help us to delete the Unused EBS Snapshot.
Keep the configuration as it is and click on create.
Now, Paste the Python code in the lambda function.
Python Code link- https://github.com/AmanPathak-DevOps/Terraform-for-AWS/blob/master/Non-Modularized/EBS-Snapshot-Cost-Optimization/ebs_snapshot_cost_optimization.py
Create a test event to run the lambda function.
Here, we need to increase the lambda timeout.
Increase the lambda timeout from 3 seconds to 10 seconds and click on Save.
Now, Here we need to update the roles and permissions for the lambda function.
We are going to work with the EC2 Instances through the lambda function.
Click on Role name. It will take you to the IAM Roles.
Click on Add permissions and then go to ‘Attach policies’.
Now, we have to create our own policy, click on ‘Create policy’.
Now in the output, the policy should look like this.
We have configured everything. Now for the test, we have to terminate our test server. So, the volume will get deleted.
Click on ‘Terminate’.
After clicking on ‘Test’ to run the Lambda function, you will see the output that EBS snapshots were deleted because the associated volume was deleted upon terminating the test server instance. Therefore, as per the code logic, any EBS snapshots whose volumeID was not found will be deleted.
In the AWS Console, no snapshots were found.
Congratulations, fearless cloud warriors! By implementing our cost optimization solution, you’ve unlocked the gateway to significant AWS savings. But wait, there’s more! Remember to regularly monitor and optimize your cloud resources for a prosperous cloud journey. Our blog is just the beginning — follow us for more AWS adventures and uncharted cost-saving territories!
It’s done bruh
If you have any other queries, feel free to reach out to me on
LinkedIn Profile: https://www.linkedin.com/in/aman-devops/
GitHub Profile: https://github.com/AmanPathak-DevOps
Happy Learning
Aman Pathak