Last active
December 1, 2022 10:56
-
-
Save toabctl/5aa7c317998cb4e870ff11f4558eb94f to your computer and use it in GitHub Desktop.
Get the total amount of snapshots in GiB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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