AWS AMI Cleanup
This gem provides the cleanup_amis script that allows deregistering unused AMIs. The IAM user running the command must have at the very least the following permissions:
- ec2:DescribeImages
- ec2:DescribeLaunchTemplateVersions
- ec2:DescribeInstances
- ec2:DeregisterImage
- ec2:DeleteSnapshot
- autoscaling:DescribeAutoScalingGroups
Script should be invoked as follows:
cleanup_amis clean_amis --ami_name 'my-ami' --ami_owner 'self'
Where ami_owner can be a combination of AWS account IDs, self, amazon, and aws-marketplace.
Additionally you can provide the following arguments:
number_of_amis_to_keepto specify how many AMIs to keep (default is 3).regionfor the AWS region (default isus-east-1).dry_runfor running without deleting any resources in AWS.skip_image_under_use_verificationfor skipping verification on whether the AMI is being used by any auto scaling group or reserved EC2 instance.