Created
May 20, 2014 09:03
-
-
Save muhqu/1c1170d6a051bdf9f824 to your computer and use it in GitHub Desktop.
ShellScript to output EBS Snapshots that are no longer referenced by AMIs
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
#!/bin/bash | |
aws ec2 describe-snapshots --owner-ids $AWS_ACCOUNT_ID > snapshots.json | |
aws ec2 describe-images --owners $AWS_ACCOUNT_ID > images.json | |
cat snapshots.json \ | |
| jq '.Snapshots[] | select(.Description//""|startswith("Created by CreateImage"))' \ | |
> snapshot-to-ami.json | |
cat images.json \ | |
| jq '.Images[]|select(.RootDeviceType == "ebs")| {ImageId, SnapshotId:.BlockDeviceMappings[0].Ebs.SnapshotId}' \ | |
> ami-to-snapshot.json | |
cat snapshot-to-ami.json ami-to-snapshot.json \ | |
| jq -s 'group_by(.SnapshotId) | .[] | {SnapshotId:.[0].SnapshotId, ImageId: (.[].ImageId//null)} ' \ | |
> snapshot-ami-merge.json | |
cat snapshot-ami-merge.json \ | |
| jq -r 'select(.ImageId == null) | .SnapshotId' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, man! It's working well, does not touch any snapshots, used in existing AMI(s)