Last active
July 31, 2018 14:26
-
-
Save Slakah/d19472f1e84213f5279984960157e594 to your computer and use it in GitHub Desktop.
Assume a AWS STS role using the AWS credentials environment variables
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 | |
set -ue | |
readonly roleArn="$1" | |
readonly durationSeconds="3600" # 1 hours | |
readonly roleSessionName="$USER-local" | |
# Use default profile to log in | |
unset AWS_ACCESS_KEY_ID | |
unset AWS_SECRET_ACCESS_KEY | |
unset AWS_SESSION_TOKEN | |
unset AWS_PROFILE | |
readonly creds="$(aws sts assume-role --role-arn $roleArn --role-session-name $roleSessionName --duration-seconds $durationSeconds --output json)" | |
readonly accessKeyId=$(echo "$creds" | jq -r .Credentials.AccessKeyId) | |
readonly secretAccessKey=$(echo "$creds" | jq -r .Credentials.SecretAccessKey) | |
readonly sessionToken=$(echo "$creds" | jq -r .Credentials.SessionToken) | |
echo "export AWS_ACCESS_KEY_ID=\"$accessKeyId\"" | |
echo "export AWS_SECRET_ACCESS_KEY=\"$secretAccessKey\"" | |
echo "export AWS_SESSION_TOKEN=\"$sessionToken\"" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment