Last active
August 29, 2015 13:56
-
-
Save jonatw/9247168 to your computer and use it in GitHub Desktop.
this script allows ec2 instances to obtain iam role security credentials by query instance meta-data api
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
#!/bin/bash | |
function get_iam_role_credentials(){ | |
BASE_URL='http://169.254.169.254/latest/meta-data/' | |
export AWS_DEFAULT_REGION=`curl -s $BASE_URL/placement/availability-zone | sed -e 's:\([0-9][0-9]*\)[a-z]*\$:\\1:'` | |
export AWS_ROLE_NAME=`curl -s $BASE_URL/iam/security-credentials/` | |
export AWS_ACCESS_KEY_ID=`curl -s $BASE_URL/iam/security-credentials/$ROLE_NAME | grep AccessKeyId | awk '{print $3}' | cut -d '"' -f 2` | |
export AWS_SECRET_ACCESS_KEY=`curl -s $BASE_URL/iam/security-credentials/$ROLE_NAME | grep SecretAccessKey | awk '{print $3}' | cut -d '"' -f 2` | |
export AWS_SECURITY_TOKEN=`curl -s $BASE_URL/iam/security-credentials/$ROLE_NAME | grep Token | awk '{print $3}' | cut -d '"' -f 2` | |
} | |
get_iam_role_credentials |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment