Last active
December 15, 2015 15:29
-
-
Save mojodna/5282595 to your computer and use it in GitHub Desktop.
EC2 metadata
This file contains 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
# Get the EC2 region from an instance, because ec2metadata only includes the availability zone (which is close, but not close enough). | |
REGION=$(curl http://169.254.169.254/latest/dynamic/instance-identity/document|grep region|awk -F\" '{print $4}') | |
# extended ec2metadata, including tags (requires an IAM role with ec2:DescribeTags) | |
list_instances -r $REGION -H T:Name,ID,Hostname,State -f "instance-id=$(ec2metadata --instance-id)" | |
export HOST=$(list_instances -r $REGION -H T:Name,ID,Hostname,State -f "instance-id=$(ec2metadata --instance-id)" | grep running | awk '{print $1}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment