AWS EBS Cost Optimization using Lambda & Boto3
In screenshots ec2-runnings.png contains the before lambda function trigggering the instance and in ec2-stopped.png contains after lambda triggering the instance .
This project focuses on optimizing AWS EBS storage costs by automatically identifying and deleting unused/stale EBS snapshots.The solution uses AWS Lambda, Boto3 (Python SDK). To perform automated cleanup .
In AWS environments
- In AWS acc EBS often remain even after volumes or EC2 isntance are deleted
- These stale snapshots ofter incur storage costs
Goal: Automatically detect and delete unused EBS snapshots to reduce AWS costs.
- AWS Lambda – Serverless execution of cleanup logic
- Amazon EC2 – Source of EBS volumes and snapshots
- Amazon EBS – Block storage snapshots
- AWS IAM – Permissions for secure access
- Python (Boto3) – AWS SDK for automation
- Collect running EC2 instance IDs
- Iterate through all snapshots
- Validate snapshot → volume → instance relationship
- Safely delete unused/stale snapshots
- Handle exceptions like deleted volumes
- Lambda function runs manual or via schedule
- Lambda fetches all running EC2 instances
- Identifies active instance IDs
- Fetches all EBS snapshots owned by the account
- Checks: -Snapshot without volume -Snapshot linked to deleted volume -Snapshot linked to unused volume
- Deletes eligible snapshots
- Logs actions to CloudWatch
- Create an unused EBS volume
- Create a snapshot of that volume
- Delete the volume
- Invoke the Lambda function
- Verify snapshot deletion via CloudWatch logs
Samidha Nitin Wani Cloud Engineer / DevOps Engineer
This project demonstrates real-world AWS automation, cost-optimization strategies, and production-ready Lambda development, making it highly suitable for cloud-focused roles.