Hidden costs on your AWS bill: How to identify and eliminate orphaned snapshots
Managing costs in the cloud can be challenging, especially when dealing with large and complex environments like AWS. As a FinOps professional with a background in cloud engineering, I’ve seen firsthand how overlooked areas like orphaned snapshots can contribute to unnecessary expenses. A few years ago, orphan snapshots were something I had overlooked in my own cloud management practices. Since then, I’ve come to understand the significant savings that can be achieved by deleting these unused backups. Here’s a actionable step-by-step guide on how to identify and eliminate orphaned snapshots to reduce your AWS bill.
What are orphaned snapshots?
Orphaned snapshots are backups of your Amazon Elastic Block Store (EBS) volumes that are no longer attached to any running instances. These snapshots can accumulate over time, leading to unnecessary storage costs. While each snapshot might seem small in isolation, together they can add up to a significant expense.
Cut costs and keep your cloud environment organized
To eliminate orphaned snapshots is crucial for several reasons:
- Cost savings: Reducing unnecessary storage can lead to substantial savings on your AWS bill. I am offering a suggestion to how you can calculate your potential savings further down in the article.
- Improved management: Keeping your AWS environment clean and organized makes it easier to manage.
- Compliance and security: Ensuring that only necessary data is retained can help with compliance and reduce the risk of data exposure.
Step-by-step guide
Step 1: inventory your snapshots
Tools Required:
Procedure:
- Using AWS Management Console:
- Navigate to the EC2 Dashboard.
- Click on Snapshots under Elastic Block Store (EBS).
- List all snapshots.
- Using AWS CLI:
- Run the command to list all snapshots:
aws ec2 describe-snapshots –owner-ids self
- Run the command to list all snapshots:
- Using AWS SDKs:
- Use the relevant SDK for your preferred programming language to fetch the list of snapshots.
- Using Third-party Tools:
- Integrate your cloud account with tools like CloudHealth or CloudCheckr to automatically list and manage snapshots.
Step 2: Identify orphaned snapshots
Tools Required:
- AWS resource tagging
- Custom scripts
Procedure:
- Tagging and tracking:
- Ensure that all snapshots and their parent volumes are appropriately tagged when created.
- Use tags to correlate snapshots with active instances or volumes.
- Custom scripts:
- Write a script to identify orphaned snapshots. The script should:
- List all snapshots.
- Check if the parent volume of each snapshot still exists.
- Check if the snapshot is associated with any active instance.
- Example in Python using Boto3 (AWS SDK for Python):
- Write a script to identify orphaned snapshots. The script should:
import boto3 ec2 = boto3.client('ec2') snapshots = ec2.describe_snapshots(OwnerIds=['self'])['Snapshots'] volumes = ec2.describe_volumes()['Volumes'] volume_ids = [volume['VolumeId'] for volume in volumes] orphaned_snapshots = [snapshot for snapshot in snapshots if snapshot['VolumeId'] not in volume_ids] for orphaned_snapshot in orphaned_snapshots: print(f"Orphaned Snapshot ID: {orphaned_snapshot['SnapshotId']}")
Step 3: Evaluate snapshots for deletion
Considerations:
- Verify if the snapshot is part of any backup or disaster recovery plan.
- Check if the snapshot is required for compliance or auditing purposes.
- Confirm with relevant stakeholders before deletion.
Step 4: Delete orphaned snapshots
Procedure:
- Using AWS management console:
- Select the orphaned snapshot from the Snapshots list.
- Click on Actions and select Delete Snapshot.
- Confirm the deletion.
- Using AWS CLI:
Run the command to delete the identified orphaned snapshot:
aws ec2 delete-snapshot –snapshot-id <snapshot-id> - Using AWS SDKs:
Use the relevant SDK to programmatically delete the snapshot.
Example in Python using Boto3:for orphaned_snapshot in orphaned_snapshots: ec2.delete_snapshot(SnapshotId=orphaned_snapshot['SnapshotId']) print(f"Deleted Snapshot ID: {orphaned_snapshot['SnapshotId']}")
Step 5: Automate the process
Tools required:
Procedure:
- Create an AWS Lambda Function:
- Write a Lambda function to identify and delete orphaned snapshots periodically.
- Schedule with cloudWatch events:
- Create a CloudWatch Event to trigger the Lambda function at a regular interval (e.g., daily, weekly).
Step 6: Implement continuous monitoring
Tools Required:
- Cloud management tools
- Custom alerts
Procedure:
- Cloud management tools:
- Custom alerts:
- Set up custom alerts to notify when new orphaned snapshots are identified.
Keep your AWS costs under control
By identifying and eliminating orphaned snapshots, you can significantly reduce your AWS bill and maintain a more efficient cloud environment. Regularly auditing your AWS resources and automating snapshot management are key practices to ensure ongoing cost optimization and operational efficiency. Start implementing these steps today to keep your AWS costs under control.