Simplified AMI deletion: new feature streamlines cleanup

Michael Wittig – 03 Jul 2025

For years, deleting an Amazon Machine Image (AMI) required a cumbersome two-step process: first deregistering the AMI, then manually deleting the underlying EBS snapshots. Forgetting that second step was costly—orphaned snapshots would accumulate, causing AWS bills to grow steadily over time.

Simplified AMI deletion

A recent AWS feature release caught my attention: Amazon EC2 now enables you to delete underlying EBS snapshots when deregistering AMIs. As the author of aws-amicleaner, a tool designed to clean up AMIs based on configurable rules, I’m excited about the operational improvements this brings.

Streamlined implementation

With this new feature, you can now delete an AMI along with its associated snapshots in a single API call. Here’s a JavaScript implementation using the AWS SDK v3:

import { EC2Client, DeregisterImageCommand } from '@aws-sdk/client-ec2';

export async function deleteAMI(amiId) {
const ec2 = new EC2Client({});
return ec2.send(new DeregisterImageCommand({
ImageId: amiId,
DeleteAssociatedSnapshots: true
}));
}

Benefits of the new approach

This enhancement eliminates the need for at least two additional API calls that were previously required to:

  1. Retrieve the AMI’s block device mappings
  2. Delete each associated snapshot individually

The result is a more efficient, reliable AMI cleanup process that reduces both API overhead and the risk of orphaned resources.

Conclusion

This AWS feature represents a significant improvement for infrastructure management. AMI deletion is now faster, more reliable, and less prone to human error—a welcome change for anyone managing EC2 images at scale.

Michael Wittig

Michael Wittig

I’ve been building on AWS since 2012 together with my brother Andreas. We are sharing our insights into all things AWS on cloudonaut and have written the book AWS in Action. Besides that, we’re currently working on bucketAV, attachmentAV, HyperEnv, and marbot.

Here are the contact options for feedback and questions.

Further reading