Created
May 20, 2021 22:47
-
-
Save kevhill/bd5c4793fc046f3e8a7e8290927b0404 to your computer and use it in GitHub Desktop.
source this to ask for an MFA code, then load aws session tokens into env
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 | |
unset AWS_ACCESS_KEY_ID | |
unset AWS_SECRET_ACCESS_KEY | |
MFA_ARN=$(aws sts get-caller-identity --output json | jq -r '.Arn' | sed 's/user/mfa/g') | |
echo Enter your MFA code | |
read MFA_CODE | |
SESSION_INFO=$(aws sts get-session-token --output json --token-code $MFA_CODE --serial-number $MFA_ARN) | |
#echo $SESSION_INFO | |
export AWS_ACCESS_KEY_ID=$(echo $SESSION_INFO | jq -r '.Credentials.AccessKeyId') | |
export AWS_SECRET_ACCESS_KEY=$(echo $SESSION_INFO | jq -r '.Credentials.SecretAccessKey') | |
export AWS_SESSION_TOKEN=$(echo $SESSION_INFO | jq -r '.Credentials.SessionToken') | |
echo "Successfully updated session token." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment