Created
September 22, 2014 17:18
-
-
Save rafaelfelini/5467c3a69d72c677bbed to your computer and use it in GitHub Desktop.
Get aws ec2 instance name via tag.
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
export AWS_ACCESS_KEY_ID= | |
export AWS_SECRET_ACCESS_KEY= | |
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 -f3`" | |
echo "hostname=$TAG_VALUE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment