Created
September 30, 2019 20:23
-
-
Save libertyy/4b5d8f97954ae8973f69d1a91a25a074 to your computer and use it in GitHub Desktop.
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 | |
while getopts ":a:r:p" opt; do | |
case ${opt} in | |
a ) | |
account=$OPTARG | |
;; | |
r ) | |
rolename=$OPTARG | |
;; | |
\? ) | |
echo "Invalid option: $OPTARG" 1>&2 | |
;; | |
: ) | |
echo "Invalid option: $OPTARG requires an argument" 1>&2 | |
;; | |
esac | |
done | |
if [ $OPTIND -ne 5 ]; then | |
echo "Neded args not found" | |
exit 1 | |
fi | |
shift $((OPTIND -1)) | |
aws_result=$(aws sts assume-role --role-arn arn:aws:iam::$account:role/$rolename --role-session-name "STS_Session") | |
AWS_SESSION_TOKEN="$(echo $aws_result | jq -r .Credentials.SessionToken)" | |
AWS_SECRET_ACCESS_KEY=$(echo $aws_result | jq -r .Credentials.SecretAccessKey) | |
AWS_ACCESS_KEY_ID=$(echo $aws_result | jq -r .Credentials.AccessKeyId) | |
echo "export AWS_SESSION_TOKEN=\"$AWS_SESSION_TOKEN\"" | |
echo "export AWS_SECRET_ACCESS_KEY=\"$AWS_SECRET_ACCESS_KEY\"" | |
echo "export AWS_ACCESS_KEY_ID=\"$AWS_ACCESS_KEY_ID\"" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment