Hidden costs on your AWS bill: How to identify and eliminate orphaned snapshots

Read More >

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
  • 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:

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):
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:

  1. Create an AWS Lambda Function:
    • Write a Lambda function to identify and delete orphaned snapshots periodically.
  2. 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:

  1. Cloud management tools:
    • Use tools like Zesty or Torque to continuously monitor and report on orphaned snapshots.
  2. Custom alerts:
    • Set up custom alerts to notify when new orphaned snapshots are identified.

How to estimate the potential savings

In order to obtain a rough estimate of how much you can save from removing orphaned snapshots, you’ll need to consider the following factors:

  1. Number of orphaned snapshots:
    • Identify how many orphaned snapshots exist in your environment.
  2. Size of each snapshot:
    • Determine the size (in GB) of each snapshot.
  3. Cost per GB:
    • Find out the storage cost per GB for your cloud provider (e.g., AWS charges $0.05 per GB per month for EBS snapshots).
  4. Duration:
    • Estimate how long these snapshots have been orphaned and accumulating costs.

Example calculation

Step 1: Identify number of orphaned snapshots

Let’s say you have identified 100 orphaned snapshots.

Step 2: Determine the size of each snapshot

Assume the average size of each snapshot is 100 GB.

Step 3: Find cost per GB

AWS charges $0.05 per GB per month for EBS snapshots.

Step 4: Estimate the duration

Assume the snapshots have been orphaned for 6 months.

Calculation

  1. Total storage used by orphaned snapshots:
    Total Storage=Number of Snapshots×Average Size of Each Snapshot\text{Total Storage} = \text{Number of Snapshots} \times \text{Average Size of Each Snapshot}

    Total Storage=100×100 GB=10,000 GB\text{Total Storage} = 100 \times 100 \text{ GB} = 10,000 \text{ GB}

  2. Monthly cost:
    Monthly Cost=Total Storage×Cost per GB\text{Monthly Cost} = \text{Total Storage} \times \text{Cost per GB}

    Monthly Cost=10,000 GB×$0.05 per GB=$500\text{Monthly Cost} = 10,000 \text{ GB} \times \$0.05 \text{ per GB} = \$500

  3. Total cost over 6 months:
    Total Cost=Monthly Cost×Duration (in months)\text{Total Cost} = \text{Monthly Cost} \times \text{Duration (in months)}

    Total Cost=$500×6=$3,000\text{Total Cost} = \$500 \times 6 = \$3,000

Savings

By identifying and removing these 100 orphaned snapshots, you could save approximately $3,000 over a 6-month period.

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.