Skip to content

Instantly share code, notes, and snippets.

@katzefudder
Last active May 14, 2020 14:52
Show Gist options
  • Save katzefudder/54fc46a57c5c21e05dc3384342f81921 to your computer and use it in GitHub Desktop.
Save katzefudder/54fc46a57c5c21e05dc3384342f81921 to your computer and use it in GitHub Desktop.
Check for a TAG on your EC2 instance in AWS
#!/bin/bash
TAG_NAME="$1"
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`"
echo $TAG_VALUE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment