amazon-web-servicesaws-cli

How to bulk delete multiple AWS snapshots using AWS CLI?


So the command for deleting a AWS Snapshot using SnapshotID is as below

aws ec2 delete-snapshot --snapshot-id snap-1234567890abcdef0 

I have a list of 400 snapshot IDs that needs deletion. What command should I use to bulk delete them using SnapshotID.

**PS: None of the snapshots are tagged.


Solution

  • Here's a solution that might sound silly, but is highly effective...

    I typically create an Excel spreadsheet with a list of IDs in the first column.

    I then create a second column with a formula that contains the full command, with a reference to the first column that inserts the ID at the appropriate place. I then Copy Down the formula for all lines.

    To test the formula, I copy the first line and paste it into my shell to confirm that it works as expected.

    I then paste all the lines generated by the formula into a text file and then execute the text file in the shell. It will run faster if you do it from an Amazon EC2 instance since it decreases network latency, but running it from your own computer will work just as well. Simply go grab a cup of coffee.

    If the thought of using Excel abhors you, then you could write a simple script in Python that iterates through the list and calls the delete_snapshot() command.