To get AMI ID with tags

aws ec2 describe-images –filter Name=tag:amitype,Values=autoscale –output text | grep -i ami | awk ‘{ print  $5, $7 }’ | awk ‘NR==1{print $1}’

Modify the “Name=tag:amitype,Values=autoscale” Section with your own tags.

Find Snapshots associated with an AMI

aws ec2 describe-images –image-ids <amiid> –output text –query Images[*].BlockDeviceMappings[*].Ebs.SnapshotId’

Replace “<amiid>” with the AMI ID you need.

To Deregister an AMI

aws ec2 deregister-image –image-id <amiid>

Replace “<amiid>” with the AMI ID you need to deregister.

To remove a snapshot 

aws ec2 delete-snapshot –snapshot-id <snapshot_id>

Replace “<snapshot_id>” with the Snapshot ID you need to remove.

 

Bash script to remove AMI’s older than 7 days and Snapshots associated with this AMI’s – link

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s