Created
April 12, 2017 12:32
-
-
Save lewismarshall/2fba62f98fc7b4280d04067ada57b5ab to your computer and use it in GitHub Desktop.
Get aws environment variables from an aws-profile and role
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
function aws-ar() { | |
local profile=${1:-hod-central} | |
local role_arn=$(grep ${profile} ~/.aws/credentials -A 3 | grep role_arn | cut -d'=' -f2) | |
local creds_json=$(aws sts assume-role --output json --role-arn ${role_arn} --profile ${profile} --role-session-name ${profile} ) | |
aws-unset | |
export AWS_ACCESS_KEY_ID=$(echo ${creds_json} | jq -r '.Credentials.AccessKeyId') | |
export AWS_SECRET_ACCESS_KEY=$(echo ${creds_json} | jq -r '.Credentials.SecretAccessKey') | |
export AWS_SECURITY_TOKEN=$(echo ${creds_json} | jq -r '.Credentials.SessionToken') | |
export AWS_SESSION_EXPIRE=$(echo ${creds_json} | jq -r '.Credentials.Expiration') | |
export AWS_SESSION_TOKEN="${AWS_SECURITY_TOKEN}" | |
} | |
function aws-unset() { | |
unset AWS_ACCESS_KEY_ID | |
unset AWS_SECRET_ACCESS_KEY | |
unset AWS_SECURITY_TOKEN | |
unset AWS_SESSION_EXPIRE | |
unset AWS_SESSION_TOKEN | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment