Skip to content

Instantly share code, notes, and snippets.

@z0mbix
Created July 7, 2015 15:12
Show Gist options
  • Save z0mbix/0de0d3aeb6f9c93e49eb to your computer and use it in GitHub Desktop.
Save z0mbix/0de0d3aeb6f9c93e49eb to your computer and use it in GitHub Desktop.
Get an Ec2 instance's role from a tag
#!/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