Skip to content

Instantly share code, notes, and snippets.

@nqbao
Created December 28, 2017 19:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nqbao/647827a2a8cafc43a03a8ebb68abfc96 to your computer and use it in GitHub Desktop.
Save nqbao/647827a2a8cafc43a03a8ebb68abfc96 to your computer and use it in GitHub Desktop.
A small python script to wipe out all AMI. Be extremely careful when you run this.
import boto3
ec2 = boto3.client('ec2')
images = ec2.describe_images(Owners=['self'])
for image in images['Images']:
if image['State'] == 'available':
snapshots = image['BlockDeviceMappings']
print "Deleting %s - %s" % (image['ImageId'], image['Name'])
ec2.deregister_image(ImageId=image['ImageId'])
for s in snapshots:
if 'Ebs' in s:
if 'SnapshotId' in s['Ebs']:
print "Deleting %s" % s['Ebs']['SnapshotId']
ec2.delete_snapshot(SnapshotId=s['Ebs']['SnapshotId'])
else:
print image['State']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment