Skip to content

Instantly share code, notes, and snippets.

@famousgarkin
Last active August 27, 2018 05:44
Show Gist options
  • Save famousgarkin/2bdd91affb609481c8118e839b804719 to your computer and use it in GitHub Desktop.
Save famousgarkin/2bdd91affb609481c8118e839b804719 to your computer and use it in GitHub Desktop.
AWS orphaned AMI snapshots cleanup
#!/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
@abdidarmawan007
Copy link

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

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