Last active
August 27, 2018 05:44
-
-
Save famousgarkin/2bdd91affb609481c8118e839b804719 to your computer and use it in GitHub Desktop.
AWS orphaned AMI snapshots cleanup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env sh | |
# https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-snapshots.html | |
snapshots=$( \ | |
aws ec2 describe-snapshots \ | |
--region eu-central-1 \ | |
--owner-id $OWNER_ID \ | |
--filters 'Name=description,Values="Created by CreateImage*",Name=status,Values=completed' | |
) | |
ids=$( | |
echo $snapshots | jq '.Snapshots[]|.SnapshotId' --raw-output | |
) | |
# https://docs.aws.amazon.com/cli/latest/reference/ec2/delete-snapshot.html | |
for id in $ids | |
do | |
aws ec2 delete-snapshot --snapshot-id $id | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
have error
./aws-orphaned-ami-snapshots-cleanup.sh
An error occurred (InvalidSnapshot.NotFound) when calling the DeleteSnapshot operation: None
An error occurred (InvalidSnapshot.NotFound) when calling the DeleteSnapshot operation: None
An error occurred (InvalidSnapshot.NotFound) when calling the DeleteSnapshot operation: None
An error occurred (InvalidSnapshot.NotFound) when calling the DeleteSnapshot operation: None