How to keep only the last N images of an EC2 instance backup set

You want to regularly backup your EC2 instances, but only keep the last N images so that you can retain an isolated use case oriented set of images in an orderly fashion.

Step-by-step guide

This can be achieved by using the EC2 Image task's Grow & Prune Image Backup Set action as follows:

  1. Specify the Instance ID (or a Filters JSON) to select the instance(s) you want to retain backups for.

  2. Choose an applicable Backup Set name for your use case so that you can retain different sets and identify the images in the AWS Management Console (they will be automatically tagged with that name).

  3. Specify the Backup Retention number N (the number of images that should be retained in this backup set).

  4. Arrange for the Bamboo build to trigger at an interval applicable for your use case, for example via cron-based scheduling to retain daily backups of your instances, or after you have pushed changes to your repository to backup your instances before deploying new code.