Created
December 1, 2020 04:31
-
-
Save franzwong/b194a4b6101f3db219926d7e4ec5f833 to your computer and use it in GitHub Desktop.
AWS get session token with OTP
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
#!/bin/bash | |
SERIAL_NUMBER=$1 | |
OTP=$2 | |
PROFILE=$3 | |
CREDENTIALS=$(aws sts get-session-token \ | |
--serial-number ${SERIAL_NUMBER} \ | |
--token-code ${OTP} \ | |
--query 'Credentials.[AccessKeyId,SecretAccessKey,SessionToken]' \ | |
--output text) | |
AWS_ACCESS_KEY_ID=$(echo $CREDENTIALS | awk '{print $1}') | |
AWS_SECRET_ACCESS_KEY=$(echo $CREDENTIALS | awk '{print $2}') | |
AWS_SESSION_TOKEN=$(echo $CREDENTIALS | awk '{print $3}') | |
aws configure set profile.${PROFILE}.aws_access_key_id ${AWS_ACCESS_KEY_ID} | |
aws configure set profile.${PROFILE}.aws_secret_access_key ${AWS_SECRET_ACCESS_KEY} | |
aws configure set profile.${PROFILE}.aws_session_token ${AWS_SESSION_TOKEN} | |
export AWS_PROFILE=${PROFILE} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment