Created
December 18, 2018 14:51
-
-
Save solocommand/6d0a483417f67d192418c67739b44108 to your computer and use it in GitHub Desktop.
Amazon STS MFA Authentication
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 | |
MFA_SERIAL=arn:aws:iam::TRUNCATED:mfa/TRUNCATED | |
read -p "MFA Code: " MFA_CODE | |
aws sts get-session-token --serial-number $MFA_SERIAL --token-code $MFA_CODE > ~/.aws/l0creds | |
SECRET_ACCESS_KEY=$(jq -r '.Credentials.SecretAccessKey' ~/.aws/l0creds) | |
SESSION_TOKEN=$(jq -r '.Credentials.SessionToken' ~/.aws/l0creds) | |
ACCESS_KEY_ID=$(jq -r '.Credentials.AccessKeyId' ~/.aws/l0creds) | |
echo -e "\n[l0_$ACCESS_KEY_ID]" >> ~/.aws/credentials | |
echo -e "aws_access_key_id = $ACCESS_KEY_ID" >> ~/.aws/credentials | |
echo -e "aws_secret_access_key = $SECRET_ACCESS_KEY" >> ~/.aws/credentials | |
echo -e "aws_session_token = $SESSION_TOKEN" >> ~/.aws/credentials | |
export AWS_PROFILE=l0_$ACCESS_KEY_ID | |
bash |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment