Last active
January 12, 2017 01:23
-
-
Save ashb/c59152abc941bd3658da to your computer and use it in GitHub Desktop.
Find un-used 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 -e | |
set -o pipefail | |
# File 1 is the list of our AMIs | |
# File 2 is the list of AMIs used by our instances | |
# Column 1 is an image of ours that is not in use | |
# Column 2 is an AMI that is in use that isn't one of ours | |
# Column 3 is the list of our AMIs that are in use. | |
comm -23 \ | |
<(aws ec2 describe-images --owners self | jq -r ' [.Images[].ImageId] | sort | unique | .[]') \ | |
<(aws ec2 describe-instances | jq -r '[.Reservations[].Instances[].ImageId] | sort | unique | .[]') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for the
<( ... )
construct! I've wanted that so many times, but not known about it!