-
-
Save hflamboauto1/0811ec09f9e9ad0840a8dfd99d3e6665 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
ROLE=${1:-} | |
if [ -z "$ROLE" ]; then | |
echo "usage: $0 <role arn> [session name]" | |
exit 1 | |
fi | |
ROLE_NAME=${ROLE##*/} | |
SESSION_NAME=${2:-aws-$ROLE_NAME} | |
STS=$(aws sts assume-role --role-arn "$ROLE" --role-session-name "$SESSION_NAME") | |
aws_key_id=$(echo "$STS" |grep "AccessKeyId" |sed 's/\(.*\: \)//') | |
aws_secret_key=$(echo "$STS" |grep "SecretAccessKey" |sed 's/\(.*\: \)//' |sed 's/,$//') | |
aws_session_token=$(echo "$STS" |grep "SessionToken" |sed 's/\(.*\: \)//' |sed 's/,$//') | |
echo -e "export AWS_ACCESS_KEY_ID=$aws_key_id | |
export AWS_SECRET_ACCESS_KEY=$aws_secret_key | |
export AWS_SESSION_TOKEN=$aws_session_token" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment