Created
January 28, 2021 07:21
-
-
Save inkz/00c0fbbab18d350916087ebb36ba866c to your computer and use it in GitHub Desktop.
AWS STS get-session-token for MFA Bash script
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
# usage . aws-2fa.sh 1234 | |
# unset previous session params | |
unset AWS_ACCESS_KEY_ID | |
unset AWS_SECRET_ACCESS_KEY | |
unset AWS_SESSION_TOKEN | |
# ARN value | |
arn='arn-value-here' | |
# get new session token from AWS | |
aws_sts_info=$(aws sts get-session-token --serial-number ${arn} --token-code $1) | |
# set new session params | |
export AWS_ACCESS_KEY_ID=$(echo ${aws_sts_info} | jq -r .Credentials.AccessKeyId) | |
export AWS_SECRET_ACCESS_KEY=$(echo ${aws_sts_info} | jq -r .Credentials.SecretAccessKey) | |
export AWS_SESSION_TOKEN=$(echo ${aws_sts_info} | jq -r .Credentials.SessionToken) | |
echo "AWS Session is set!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment