Created
June 17, 2019 14:58
-
-
Save ldnunes/c282777cbf090d9a7691485d57f91187 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 | |
# usage: . aws-cli-enable-mfa-token.sh ONE_TIME_PASS_CODE_FROM_YOUR_MFA_DEVICE | |
# IMPORTANT: there's a dot before the script name, to set the variables on the current shell. | |
ONE_TIME_PASS_CODE="$1" | |
MFA_DEVICE_SERIAL_CODE="" # use "aws iam list-mfa-devices --user-name YOUR_USERNAME" to find out what is your MFA device serial number. It's also on your security credentials user page on AWS console, IAM service. | |
AWS_JSON=$(aws sts get-session-token --serial-number "$MFA_DEVICE_SERIAL_CODE" --token-code "$ONE_TIME_PASS_CODE") | |
export AWS_ACCESS_KEY_ID=$(echo $AWS_JSON | jq -r .Credentials.AccessKeyId) | |
export AWS_SECRET_ACCESS_KEY=$(echo $AWS_JSON | jq -r .Credentials.SecretAccessKey) | |
export AWS_SESSION_TOKEN=$(echo $AWS_JSON | jq -r .Credentials.SessionToken) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment