Last active
February 22, 2017 14:20
-
-
Save jkordish/4392db9993f99f65dc79 to your computer and use it in GitHub Desktop.
Shellscript to provide all the required AWS Credentials for instances. Handy for sourcing into scripts.
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
#!/bin/bash -e | |
# /etc/profile.d/creds.sh | |
iam_role=$(/usr/bin/curl -s http://169.254.169.254/latest/meta-data/iam/security-credentials/) | |
export AWS_ACCOUNT_ID=$(/usr/bin/curl -s http://169.254.169.254/latest/dynamic/instance-identity/document | /usr/bin/jq -r .accountId) | |
export AWS_DEFAULT_REGION=$(/usr/bin/curl -s http://169.254.169.254/latest/dynamic/instance-identity/document | /usr/bin/jq -r .region) | |
export AWS_ACCESS_KEY_ID=$(/usr/bin/curl -s http://169.254.169.254/latest/meta-data/iam/security-credentials/$iam_role | /usr/bin/jq -r .AccessKeyId) | |
export AWS_SECRET_ACCESS_KEY=$(/usr/bin/curl -s http://169.254.169.254/latest/meta-data/iam/security-credentials/$iam_role | /usr/bin/jq -r .SecretAccessKey) | |
export AWS_SECURITY_TOKEN=$(/usr/bin/curl -s http://169.254.169.254/latest/meta-data/iam/security-credentials/$iam_role | /usr/bin/jq -r .Token) | |
export AWS_SESSION_TOKEN=$AWS_SECURITY_TOKEN |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment