Skip to content

Instantly share code, notes, and snippets.

@denzfarid
Forked from ashb/unused-amis.sh
Created January 12, 2017 01:23
Show Gist options
  • Select an option

  • Save denzfarid/74ee8912b28996c7c96415bf991944e1 to your computer and use it in GitHub Desktop.

Select an option

Save denzfarid/74ee8912b28996c7c96415bf991944e1 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 | .[]')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment