Skip to content

Instantly share code, notes, and snippets.

@lacerdaeduardo
Created April 29, 2020 13:24
Show Gist options
  • Save lacerdaeduardo/b079266e5e07caf11c009f12835f6780 to your computer and use it in GitHub Desktop.
Save lacerdaeduardo/b079266e5e07caf11c009f12835f6780 to your computer and use it in GitHub Desktop.
PROFILE=profile
MFA_SERIAL=xxx
USER=xxx
RESULT=$(aws sts get-session-token --serial-number arn:aws:iam::${MFA_SERIAL}:mfa/${USER} --token-code $1 --profile ${PROFILE})
ACCESS_KEY_ID="$(echo $RESULT | jq '.Credentials.AccessKeyId' -r)"
SECRET_KEY=$(echo $RESULT | jq '.Credentials.SecretAccessKey' -r)
TOKEN=$(echo $RESULT | jq '.Credentials.SessionToken' -r)
aws configure set aws_access_key_id $ACCESS_KEY_ID
aws configure set aws_secret_access_key $SECRET_KEY
aws configure set aws_session_token $TOKEN
echo "CREDENTIALS SET.......... "
echo "ENV - DEV "
echo "ACCESS_KEY: $ACCESS_KEY_ID"
echo "SECRET: $SECRET_KEY"
echo "TOKEN: $TOKEN"
echo ".........................."
@lacerdaeduardo
Copy link
Author

lacerdaeduardo commented Apr 29, 2020

Steps to run this file:

  1. Install jq before run this script (using brew or apt-get)
    brew install jq
  2. Use chmod 755 to allow it to run
    chmod 755 ./set-awscli-keys-and-token.sh
    call the script:

./set-awscli-keys-and-token.sh **<TOKEN>**

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment