Skip to content

Instantly share code, notes, and snippets.

@andreyev
Created June 18, 2021 16:47
Show Gist options
  • Save andreyev/e2590962f2fbebcdcaf8626f34ce2efb to your computer and use it in GitHub Desktop.
Save andreyev/e2590962f2fbebcdcaf8626f34ce2efb to your computer and use it in GitHub Desktop.
compare and instances reservations on every region of aws
aws ec2 describe-regions --region us-east-1 | jq -r '.Regions[].RegionName' | sort | while read REGION; do aws --region $REGION ec2 describe-instances | jq -r '.Reservations[].Instances[]|select(.State.Name|match("running"))|"\(.InstanceType)"'| sort | uniq -c > /tmp/instances; aws --region $REGION ec2 describe-reserved-instances | jq -r '.ReservedInstances[]|select(.State|match("active"))|" \(.InstanceCount) \(.InstanceType)"'| sort > /tmp/reservations; [[ -s /tmp/instances || -s /tmp/reservations ]] && echo -ne "Region: $REGION\n-Instances:\n$(cat /tmp/instances)\n-Reservations:\n$(cat /tmp/reservations)\n"; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment