AMI de-registration with AWS Lambda and retention in Amazon EC2 Recycle Bin

Amazon EventBridge rule → AWS Lambda → Amazon EC2

This project demonstrates a pattern to deregister and retain expired AMI and its snapshot with AWS Lambda and Amazon EC2 Recycle Bin

In this pattern an Amazon EventBridge rule triggers an AWS Lambda function which deregisters an Amazon Machine Image (AMI), deletes the associated snapshot and moves them to the Recycle Bin for retention.
The AWS Lambda function automates the expiration of Amazon Machine Images (AMIs) by moving the AMIs and their associated snapshots to Recycle Bin. Recycle Bin is a feature of Amazon Elastic Compute Cloud (EC2) that allows you to retain AMIs that you have de-registered for a specified retention period, providing an opportunity to recover them if needed. To recover the deleted AMI, its associated snapshot should be recovered first. The Lambda function also adds corresponding tags to both, the AMI and the EBS snapshot, before moving them to Recycle Bin.

< Back to all patterns

GitHub icon Download this pattern (.zip)

GitHub icon View this pattern on GitHub


Clone repo

git clone https://github.com/aws-samples/serverless-patterns/cd serverless-patterns/ami-recycle-bin

Deploy

terraform initterraform planterraform apply


Testing

See the Github repo for detailed testing instructions.

Cleanup

terraform destroy

Created by:

Divya Vijendra Girase

Divya Vijendra Girase

I am a Cloud Infrastructure Architect at AWS and I work with our strategic customers to build, run and maintain their infrastructure on AWS.

Follow on LinkedIn