Skip to content

Instantly share code, notes, and snippets.

@hatchcanon
Created April 5, 2021 21:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hatchcanon/459ba4eaadbd6f8983581a92cdd9eaeb to your computer and use it in GitHub Desktop.
Save hatchcanon/459ba4eaadbd6f8983581a92cdd9eaeb to your computer and use it in GitHub Desktop.
bulk delete multiple AWS snapshots using AWS CLI
file="filewithsnapshotids.txt"
cat $file | tr -d '\r' | while read -r line;
do
aws ec2 delete-snapshot --snapshot-id $line
echo "Deleting snapshot $line"
done
@thermonucleardriven
Copy link

Hi There,
Thanks for the code, is this a python code?
And how do I actually run it?

Thanks.

@hatchcanon
Copy link
Author

@thermonucleardriven This is bash. You have to have the AWS CLI installed for this to work.

@hatchcanon
Copy link
Author

This code also works for deregistering AMIs.
Replace
aws ec2 delete-snapshot --snapshot-id
with
aws ec2 deregister-image --image-id

@m0fugga
Copy link

m0fugga commented Dec 2, 2022

Thanks exactly what I needed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment