Created
September 25, 2018 19:23
-
-
Save webguywalker/54aa2cbfb3d9519154c539f8086a7058 to your computer and use it in GitHub Desktop.
authenticate aws cli when mfa is enabled
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 | |
help () { | |
echo 'Usage: sh aws_mfa.sh "$mfa_arn" $mfa_code'; | |
echo "\nWhere:" | |
echo ' - $mfa_arn, is aws arn to the mfa device found in iam profile' | |
echo ' - $mfa_code, is code generated by mfa device' | |
} | |
if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then | |
help | |
exit 0 | |
fi | |
arg1="${1%\"}" #trim suffix | |
arg1="${arg1#\"}" #trim prefix | |
# variables | |
_MFA_ARN=$arg1 | |
_CODE=$2 | |
aws sts get-session-token --serial-number "$_MFA_ARN" --token-code "$_CODE" \ | |
| jq '.Credentials | ("export AWS_ACCESS_KEY_ID=" + .AccessKeyId),("export AWS_SECRET_ACCESS_KEY=" + .SecretAccessKey),("export AWS_SESSION_TOKEN=" + .SessionToken)'; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment