Created
July 7, 2015 15:12
-
-
Save z0mbix/0de0d3aeb6f9c93e49eb to your computer and use it in GitHub Desktop.
Get an Ec2 instance's role from a tag
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
#!/usr/bin/env bash | |
meta_url="http://169.254.169.254/latest/meta-data" | |
instance_id=$(curl -sf ${meta_url}/instance-id) | |
role=$(aws ec2 describe-tags --filters \ | |
"Name=resource-type,Values=instance" \ | |
"Name=resource-id,Values=${instance_id}" \ | |
"Name=key,Values=role" \ | |
| jq -r .Tags[].Value) | |
echo "role=$role" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment