Skip to content

Instantly share code, notes, and snippets.

@dserodio
Created June 26, 2018 22:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dserodio/5b93daf2d2af6ac262097cb65f354d23 to your computer and use it in GitHub Desktop.
Save dserodio/5b93daf2d2af6ac262097cb65f354d23 to your computer and use it in GitHub Desktop.
Get EC2 instance tags
# See https://stackoverflow.com/a/24549602/31493 and
# https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-tags.html
TAG_NAME="Name"
INSTANCE_ID=$(wget -qO- http://instance-data/latest/meta-data/instance-id)
REGION=$(wget -qO- http://instance-data/latest/meta-data/placement/availability-zone | sed -e 's:\([0-9][0-9]*\)[a-z]*\$:\\1:')
TAG_VALUE="`aws ec2 describe-tags --filters "Name=resource-id,Values=$INSTANCE_ID" "Name=key,Values=$TAG_NAME" --region $REGION --output=text | cut -f5`"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment