-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathdelete-ebs-snapshots.py
More file actions
23 lines (20 loc) · 1.07 KB
/
delete-ebs-snapshots.py
File metadata and controls
23 lines (20 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import boto3
AWS_ACCESS_KEY_ID = "AKIAZKCNCMWKKZRD2KW"
AWS_SECRET_ACCESS_KEY = "jzB4dlyV+63D7H8NDDb7LcxbDyNsUwKdG1oSnVO"
def cleanup_snapshots():
ec2 = boto3.client('ec2', aws_access_key_id=AWS_ACCESS_KEY_ID, aws_secret_access_key=AWS_SECRET_ACCESS_KEY)
regions = [region['RegionName'] for region in ec2.describe_regions()['Regions']]
for region in regions:
print(f"Cleaning up snapshots in {region}")
ec2 = boto3.client('ec2', region_name=region, aws_access_key_id=AWS_ACCESS_KEY_ID, aws_secret_access_key=AWS_SECRET_ACCESS_KEY)
response = ec2.describe_snapshots(OwnerIds=['self'])
snapshots = response['Snapshots']
while snapshots:
for snapshot in snapshots:
print(f"Deleting snapshot {snapshot['SnapshotId']}")
ec2.delete_snapshot(SnapshotId=snapshot['SnapshotId'])
response = ec2.describe_snapshots(OwnerIds=['self'])
snapshots = response['Snapshots']
print(f"Finished cleaning up snapshots in {region}")
if __name__ == '__main__':
cleanup_snapshots()