Created
February 14, 2017 19:20
-
-
Save mwinters0/9de7e1781723d60e6ae34016b9185180 to your computer and use it in GitHub Desktop.
Bash to get Name tag on EC2 instances
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Gets any tag value, default 'Name'. Assumes that `aws` CLI is | |
# installed, and the IAM role has Describe-Tags permissions. | |
TAG=Name | |
INSTANCE_ID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id) | |
REGION=$(curl -s http://169.254.169.254/latest/dynamic/instance-identity/document | grep region | awk -F\" '{print $4}') | |
TAG_VALUE=$(aws ec2 describe-tags --filters "Name=resource-id,Values=$INSTANCE_ID" "Name=key,Values=$TAG" --region=$REGION --output=text | cut -f5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment