skip to Main Content

How can I delete more than thousands of AMIs and snapshots in AWS for linux servers?
Is it possible to delete AMIs that were created in a specific year, for example, all AMIs created in 2020?

if i can get a solution, it will be great.

2

Answers


  1. This process is probably easier to do when using a programming language (eg Python) that using the AWS CLI, but if you are skilled in shell script then you can probably figure it out.

    I’ll give examples using boto3, but there are equivalents in the AWS CLI.

    You can use describe_images() to list the AMIs in your AWS Account. Make sure you use Owners=['self'] to only return AMIs that were created in your AWS Account. Failing to do this will list ALL AMIs in the region, including ones you didn’t create.

    You can specify filters when calling list_images() and pass a value for creation-date (that can include a wildcard, eg 2020*).

    When you find one that you wish to delete, you can use deregister_image() to make the AMI disappear. It is possible that the underlying Snapshot for the AMI still exists, so you might separately need to list and delete the Amazon EBS Snapshots that were used by the AMIs.

    You would need to write your own program that obtains a list of images (as shown above) and then decides which ones to delete.

    Login or Signup to reply.
  2. You can take a look at this open-source repository on github.

    They are creating an open-source framework for writing Runbooks using Jupyter notebooks.

    This repo has a runbook that can Copy and Delete AMI to all given AWS regions. I think it has one for copying but you can replace the copy one with delete action to delete those AMIs.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search