Created
June 7, 2017 16:22
-
-
Save empiricalthought/7d9be7f6af2f1f1fa32dd2dda8a68e71 to your computer and use it in GitHub Desktop.
Bash function to automate MFA for interactive awscli usage
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
# To use this wrapper, | |
# $ . ./mfa_wrap.sh | |
# $ mfa_wrap 123456 'aws s3 ls' | |
mfa_wrap() { | |
MFA_TOKEN="$1" | |
shift | |
SHELL_CMD=$(aws sts get-session-token \ | |
--serial-number="${AWS_MFA_SERIAL?AWS_MFA_SERIAL must be set}" \ | |
--token-code=${MFA_TOKEN} \ | |
--output=text | awk ' | |
{ | |
print "export AWS_ACCESS_KEY_ID=" $2 "; " | |
print "export AWS_SECRET_ACCESS_KEY=" $4 "; " | |
print "export AWS_SESSION_TOKEN=" $5 "; " | |
print "export AWS_SECURITY_TOKEN=" $5 "; " | |
}' && echo "$@") | |
bash <<<"$SHELL_CMD" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment