Skip to main content
All CollectionsHelpful Tips and Pointers
Preserving AMI Images Per EC2 Instance
Preserving AMI Images Per EC2 Instance

Apply "Minimum to Keep" per each originating EC2 instance when deregistering AMI images

Matt Houser avatar
Written by Matt Houser
Updated over a week ago

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: skeddly:instance-id = $(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: skeddly:instance-id 


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. 

Did this answer your question?