Simplified AMI deletion: new feature streamlines cleanup
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.
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'; |
Benefits of the new approach
This enhancement eliminates the need for at least two additional API calls that were previously required to:
- Retrieve the AMI’s block device mappings
- 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.
Further reading
- Article Cleaning up AMIs
- Article How to reduce costs for GitHub Actions?
- Tag ec2
- Tag ebs