Cloud Cost Optimization

Purpose: The purpose of this automation is to manage Amazon Elastic Block Store (EBS) snapshots within an AWS environment efficiently. EBS snapshots are essential for data backup and disaster recovery, but their manual management can be time-consuming and error-prone as the number of snapshots grows. This automation aims to streamline the process by identifying and removing unnecessary snapshots, optimizing storage usage, and reducing operational overhead.


Solution

The solution employs an AWS Lambda function written in Python, utilizing the boto3 library to interact with AWS services programmatically. Here's how it operates:

Snapshot Retrieval: Using the describe_snapshots API, the function fetches information about all EBS snapshots owned by the AWS account.

Active Instance Identification: The function then queries running EC2 instances via the describe_instances API to determine active instance IDs.

Snapshot Analysis: It iterates through each snapshot, examining its association with volumes and instances.

Orphaned Snapshot Handling: Snapshots not associated with any volume are deemed orphaned and are promptly deleted.

Unused Snapshot Handling: Snapshots associated with volumes not attached to running instances are considered unused and are deleted to free up storage resources.

Error Handling: The function incorporates error handling to gracefully manage unexpected situations, such as missing volumes or API errors

"By identifying and removing obsolete snapshots, you'll reduce the amount of stored data in Amazon S3, which is the underlying storage for EBS snapshots. Since AWS charges for S3 storage usage, eliminating unnecessary snapshots can lead to direct cost savings."

GitHub Repo