Find all snapshots created by ami where ami is deleted

amazon ec2amazon-web-services

Recently we had clean up drive in our Amazon Web Services account. We deleted more than 200 AMIs. Because snapshots for these AMIs did not to delete on delete of AMI.

How can I find list of snapshots created by AMIs where the AMI which created snapshot is deleted?

I couldnt find anything from AWS management console or AWS CLI.

Best Answer

If you have only been creating snapshots at AMI creation time, you may be able to reliably do this with the CLI or powershell tools:

  • Get all EC2 snapshots created by your AWS Account (OwnerID = your aws account)
  • Get Snapshots associated with still running Volumes
    • Of these snapshots, attempt to match their VolumeID with the VolumeID of still running Volumes. Output the SnapshotID of matches.
  • Get Orphaned Snapshots/Volumes
    • Of these snapshots, attempt to match their VolumeID with the VolumeID of still running Volumes. Output the SnapshotID of snapshots that aren't matched with still running volumes.

You'll need:

That won't identify that these volumes were generated along with AMIs that you want to delete, though... only that they've been orphaned. Consider saving yourself a lot of future headache and tag your EC2 volumes at creation time with some simple metadata about who was responsible for creating them, and what they were created for.