Skip to content

Instantly share code, notes, and snippets.

@mijdavis2
Last active October 29, 2020 21:10
Show Gist options
  • Save mijdavis2/52aadff85e52ec3b293bf639c3b218b7 to your computer and use it in GitHub Desktop.
Save mijdavis2/52aadff85e52ec3b293bf639c3b218b7 to your computer and use it in GitHub Desktop.
Get "Name" tag for all AWS EC2 instances in a region
#!/bin/bash
PROFILE=${AWS_PROFILE:-default}
TAG=${TAG:-Name}
STATE=${STATE:-running}
aws ec2 --profile ${PROFILE} describe-instances \
--filters Name=instance-state-name,Values=${STATE} | \
jq .Reservations[].Instances[].Tags | \
jq -c ".[] | select(.Key | contains(\"${TAG}\"))" | \
jq .Value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment