Created
December 28, 2017 19:27
-
-
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.
This file contains 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
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