Skeddly's "Deregister AMI Images" action includes a "Minimum to Keep" field, which will preserve a desired number of AMI images. However when deleting AMI images, it is common to want to preserve 2 or 5 or 10 AMI images from each EC2 instance.
Unfortunately, AMI images do not have a native reference to the source EC2 instance (unlike EBS snapshots which have the
Volume ID property).
To work around this limitation, we recommend adding the EC2 instance ID to the AMI image as a resource tag. Once the AMI images have the correct tags applied, "Image Grouping" can be used to preserve a minimum number of images for each originating EC2 instance.
Step 1: Add Tags When Creating AMI Images
As part of Skeddly's AMI image-creating actions, you can add tags to the AMI images. By default, Skeddly adds the following tag:
$(INSTANCEID) . When the AMI image is created, Skeddly will add the EC2 instance ID to the image.
Step 2: Enable "Image Grouping" When Deregistering AMI Images
As part of the "Deregister AMI Image" action, you can apply "Image Grouping" using a resource tag. In this case, we should use the same resource tag that was mentioned above.
Set the following fields:
- Image Grouping:
By Resource Tag
- Grouping Resource Tag Name:
There's nothing magical about the
skeddly:instance-id tag name. You can choose any tag name that you find appropriate. We just like this one.