Real-time use case to clean up an unused AMI
One way you can save costs in AWS is by cleaning up or removing old AMIs that are not in use. The process is called deregistering an AMI, and it will not impact the existing running instance, but you will not be able to launch a new instance from the AMI.
There are multiple ways to achieve the end goal (cleaning up an AMI), but the way we will do it is with a combination of Lambda and CloudWatch rules. The following are the steps you need to follow:
- The first step is to create a Lambda function. Go to the Lambda console at https://us-west-2.console.aws.amazon.com/lambda/home and click on Create Function:
- Fill in the following details:
- Function name: Give your Lambda function a name, for example,
cleanupunusedami
.- Runtime: Python3.7
- Choose or create an execution role: Choose a Create a new role with basic Lambda permissions
Click on Create function: