Skip to content

Instantly share code, notes, and snippets.

@ashb
Last active January 12, 2017 01:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ashb/c59152abc941bd3658da to your computer and use it in GitHub Desktop.
Save ashb/c59152abc941bd3658da to your computer and use it in GitHub Desktop.
Find un-used AMIs
#!/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 | .[]')
@stig
Copy link

stig commented Oct 23, 2015

Thank you for the <( ... ) construct! I've wanted that so many times, but not known about it!

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