Created
August 6, 2020 15:40
-
-
Save jamesharr/905b52e9c18bd6e533416b33ca2229d7 to your computer and use it in GitHub Desktop.
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
aws-token(){ | |
aws_token_sn=arn:aws:iam::REDACTED_ACCT_NUM:mfa/REDACTED_USER_PASSWD | |
aws_token_duration=43200 | |
export AWS_ACCESS_KEY_ID="" | |
export AWS_SECRET_ACCESS_KEY="" | |
export AWS_SESSION_TOKEN="" | |
read -p "MFA Code: " aws_token_code | |
OUT="$(aws sts get-session-token \ | |
--serial-number $aws_token_sn \ | |
--token-code $aws_token_code \ | |
--duration-seconds $aws_token_duration \ | |
--output text | |
)" | |
if [ $? -ne 0 ]; then | |
echo "ERROR: $OUT" | |
return | |
else | |
export AWS_ACCESS_KEY_ID="$(echo "$OUT" | awk '{print $2}')" | |
export AWS_SECRET_ACCESS_KEY="$(echo "$OUT" | awk '{print $4}')" | |
export AWS_SESSION_TOKEN="$(echo "$OUT" | awk '{print $5}')" | |
expire="$(echo "$OUT" | awk '{print $3}')" | |
echo "Temporary key applied and will expire $expire" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment