Created
May 22, 2020 01:25
-
-
Save cdimascio/ffb1d1e6ecaed0d458a4d3b8f4430158 to your computer and use it in GitHub Desktop.
AWS CLI set to role with MFA
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
#!/bin/bash | |
role_arn="<your_role_arn>" | |
mfa_arn="<your_mfa_arn>" | |
session_id=`date +%s000` | |
# export AWS_DEFAULT_REGION="us-east-2" | |
echo "MFA:" | |
read token_code | |
cmd=$(aws sts assume-role --role-arn "${role_arn}" --role-session-name "${session_id}" --serial-number "${mfa_arn}" --token-code "${token_code}" --query '[Credentials.AccessKeyId,Credentials.SecretAccessKey,Credentials.SessionToken]' --output text) | |
arr=(`echo ${cmd}`) | |
unset AWS_SECURITY_TOKEN | |
export AWS_ACCESS_KEY_ID=${arr[1]} | |
export AWS_SECRET_ACCESS_KEY=${arr[2]} | |
export AWS_SESSION_TOKEN=${arr[3]} | |
export AWS_SECURITY_TOKEN=${arr[3]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment