Skip to content

Instantly share code, notes, and snippets.

@rdlu
Created June 4, 2019 17:04
Show Gist options
  • Select an option

  • Save rdlu/63e8e17d9b50b19c28e646b237c88e42 to your computer and use it in GitHub Desktop.

Select an option

Save rdlu/63e8e17d9b50b19c28e646b237c88e42 to your computer and use it in GitHub Desktop.

Revisions

  1. rdlu created this gist Jun 4, 2019.
    19 changes: 19 additions & 0 deletions ask-mfa
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    #! /bin/bash
    ACCOUNT_NUM=<MY_AWS_ACCOUNT_NUM>
    ACCOUNT_USER=<MY_AWS_ACCOUNT_USER>

    aws configure --profile ask-mfa list > /dev/null
    if [ $? -eq 0 ]
    then
    read -p "Token MFA da conta $ACCOUNT_NUM/$ACCOUNT_USER: " TOKEN
    aws sts get-session-token --serial-number arn:aws:iam::$ACCOUNT_NUM:mfa/$ACCOUNT_USER --profile ask-mfa --token-code $TOKEN > ~/.aws/temp_creds.json
    aws configure --profile default set aws_access_key_id $(jq -r ".Credentials.AccessKeyId" ~/.aws/temp_creds.json)
    aws configure --profile default set aws_secret_access_key $(jq -r ".Credentials.SecretAccessKey" ~/.aws/temp_creds.json)
    aws configure --profile default set aws_session_token $(jq -r ".Credentials.SessionToken" ~/.aws/temp_creds.json)
    echo "Token gerado com sucesso. Expiração: " $(jq -r ".Credentials.Expiration" ~/.aws/temp_creds.json)
    else
    # Configuring the proxy profile
    echo " -- Type YOUR main ACCESS KEY ID and SECRET, they will be used for asking the temporary token --"
    aws configure --profile ask-mfa
    fi