Skip to content

Instantly share code, notes, and snippets.

@toabctl
Last active December 1, 2022 10:56
Show Gist options
  • Save toabctl/5aa7c317998cb4e870ff11f4558eb94f to your computer and use it in GitHub Desktop.
Save toabctl/5aa7c317998cb4e870ff11f4558eb94f to your computer and use it in GitHub Desktop.
Get the total amount of snapshots in GiB
#!/usr/bin/python3
"""
Get the total amount of GiB snapshots use and calculate the average snapshot size
Use eg. with:
AWS_DEFAULT_REGION=sa-east-1 AWS_PROFILE=my-profile ./aws-snapshots-size.py
"""
import boto3
ec2res = boto3.resource('ec2')
ec2client = boto3.client('ec2')
region_name = ec2client.meta.region_name
snapshots = ec2res.snapshots.filter(OwnerIds=['self'])
snapshots_size_total = 0
snapshots_count_total = 0
for s in snapshots:
snapshots_size_total += s.volume_size
snapshots_count_total += 1
snapshot_size_avg = snapshots_size_total / snapshots_count_total
print(f'{region_name}: Found {snapshots_count_total} total snapshots ({snapshots_size_total} GiB). Avg size: {snapshot_size_avg} GiB')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment