AWS volume snapshots, also known as EBS snapshots, are widely used to backup and restore data on Amazon EC2 as it’s quite important nowadays to stay protected, but how are these snapshots charged? How much does it cost me to remain protected? Can I somehow reduce my AWS bill by removing unused resources? Let’s answer all these questions one by one.
How AWS volume snapshots are charged
EBS snapshots are charged on a gigabyte-per-month basis, thus an important note here is to understand how they are generated and how much storage they really consume.
AWS snapshots are stored incrementally, and it means that the first snapshot of your instance is a full copy and each next snapshot is incremental, so only the changed parts (or deltas) of your EBS volume are stored.
Here is an example – there is a 200GB instance running in your account. The first snapshot that you create will also be 200GB and you will be charged for this amount of data, and if you have 205 GB of extra data (emulating a case when the initial 200GB was not changed) the next time when you create a snapshot, you will be charged for additional 5GB of snapshot storage for the second snapshot.
Free cloud cost optimization. Lifetime
Why companies continue to pay after deleting an instance in AWS
The next thing to remember is that while deleting an instance in AWS, the volume of this instance is also deleted, but the snapshots remain in the cloud, thus they become orphaned and are often just lost among the others but you still have to pay for them.
As for the pricing itself, like for all other AWS services, it varies from one region to another, but the average price is about $0.05 per GB-month of data stored. Someone would say: ‘Hey, it’s not that much!’, and he could be right, but here our main problem comes – the more snapshots you have, the higher your bill is.
Obviously, the optimal solution to this issue is policy availability that would describe how you store and retain unused snapshots, and scripts to find and clean them.
How to find and delete orphaned and unused snapshots
The process of finding orphaned snapshots is a bit complex, because you have to not only get the list of snapshots, but also get the list of volumes/AMIs and check if the snapshots are linked or not to particular volumes and images.
From AWS Console:
AWS Console is pretty poor at identifying if a snapshot is related to any existing AMI or volume, e.g. even if a volume is deleted from the cloud, the Volume ID field on the snapshots page will still have the original value, but still you can use the Snapshots page to remove unnecessary snapshots:
From AWS CLI:
To get the list of snapshots not linked to any volume:
ORPHANED_SNAPSHOT_IDS=$(comm -23 <(aws ec2 describe-snapshots --owner-ids $AWS-ACCOUNT-ID --query 'Snapshots[*].SnapshotId' --output text | tr '\t' '\n' | sort) <(aws ec2 describe-volumes --query 'Volumes[*].SnapshotId' --output text | tr '\t' '\n' | sort | uniq))
To get the list of snapshots not linked to any AMIs:
ORPHANED_SNAPSHOT_IDS=$(comm -23 <(aws ec2 describe-snapshots --owner-ids $AWS_ACCOUNT_ID --query 'Snapshots[*].SnapshotId' --output text | tr '\t' '\n' | sort) <(aws ec2 describe-images --filters Name=state,Values=available --owners $AWS_ACCOUNT_ID --query "Images[*].BlockDeviceMappings[*].Ebs.SnapshotId" --output text | tr '\t' '\n' | sort | uniq))
Use regular shell loop to remove the snapshots for volumes and AMIs:
for snapshot_id in $ORPHANED_SNAPSHOT_IDS; do echo "aws ec2 delete-snapshot --snapshot-id $snapshot_id"; done
Dozens of AWS volume snapshots are usually launched by a company engineering team on a daily basis. EBS snapshots have become a popular choice to backup and restore data on Amazon EC2. But some challenges may occur while deleting instances and companies continue to pay for them.
The ways of identifying and deleting orphaned and unused snapshots, described in the article, will help you avoid wastage, achieve optimization goals and reduce your cloud bill.
Elastic IP addresses on Amazon EC2 are free of charge, but only in case of the following rules are applied. Get more details about the rules of using Elastic IP addresses on Amazon EC2 and start to save your company’s cloud budget → ‘How to release Elastic IPs on Amazon EC2.’