Last active
November 30, 2020 05:57
-
-
Save ksato9700/d26d9c62702fbda17f0a45ea616d13e5 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
function update-awscli-mfa() { | |
if [ "x$1" = "x" ]; then | |
echo "update-awscli-mfa <mfa code>" | |
return 1 | |
fi | |
device=$(sed -n '/^\[mfa/,/^\[/p' ~/.aws/credentials|awk '$1=="aws_mfa_device"{print $3}') | |
if [ "x$device" = "x" ]; then | |
echo "no mfa profile or aws_mfa_device found in ~/.aws/credentials" | |
return 2 | |
fi | |
eval $(aws sts get-session-token --profile mfa --serial-number $device --token-code $1 | awk '$1 == "\"AccessKeyId\":" { gsub(/\"/,""); gsub(/,/,""); print "export AWS_ACCESS_KEY_ID="$2 } $1 == "\"SecretAccessKey\":" { gsub(/\"/,""); gsub(/,/,""); print "export AWS_SECRET_ACCESS_KEY="$2 } $1 == "\"SessionToken\":" { gsub(/\"/,""); gsub(/,/,""); print "export AWS_SESSION_TOKEN="$2 } ') | |
aws configure list | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment