User Tools

Site Tools


wiki:aws_cli_2fa

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
wiki:aws_cli_2fa [2024/10/23 14:34] – [AWS CLI with 2FA] add bash script antisawiki:aws_cli_2fa [2024/10/29 13:58] (current) – [See also] add aws cli commands antisa
Line 51: Line 51:
 </code>  </code> 
  
-Here's a bash script that adds the creds each time to the file. Just pass it token-code and add your serial number.+Here's a bash script that adds the creds each time to the file. Just pass it token-code and add your serial number. Remember to source it e.g. 
 +  . ~/.local/bin/aws_get_session.sh 1234
  
 <file bash aws_get_session.sh> <file bash aws_get_session.sh>
 #!/bin/bash #!/bin/bash
 +# run this script with source (.) command since we need access to 
 +# the exported AWS_PROFILE variable below in the parent shell e.g.
 +# . ~/.local/bin/aws_get_session.sh 1234
 +
 +# debug
 +# set -x
 +
 +if [ "${BASH_SOURCE[0]}" -ef "$0" ]
 +then
 +      echo "Hey, you should source this script, not execute it!"
 +      echo "e.g. '. aws_get_session.sh 1234'"
 +      exit 1
 +fi
 +
 +if [ -z $1 ];then
 +  echo "You must provide 2FA token!"
 +  return 1
 +fi
  
-#set -x 
 # colors # colors
 On_Yellow='\033[43m' On_Yellow='\033[43m'
Line 73: Line 91:
 aws_secret_access_key = $(echo "$KST" | jq '.Credentials.SecretAccessKey' | tr -d '"') aws_secret_access_key = $(echo "$KST" | jq '.Credentials.SecretAccessKey' | tr -d '"')
 aws_session_token = $(echo "$KST" | jq '.Credentials.SessionToken' | tr -d '"') aws_session_token = $(echo "$KST" | jq '.Credentials.SessionToken' | tr -d '"')
 +
 EOF EOF
  
 +# below export will only work when sourcing this script
 export AWS_PROFILE=myprofile-session export AWS_PROFILE=myprofile-session
 echo -e "Current AWS_PROFILE set to ${On_Yellow}$AWS_PROFILE${NC}" echo -e "Current AWS_PROFILE set to ${On_Yellow}$AWS_PROFILE${NC}"
Line 83: Line 103:
  
 ====== See also ====== ====== See also ======
 +    * [[wiki:aws_cli_commands|aws cli commands]]
 ====== References ====== ====== References ======
   * https://stackoverflow.com/questions/34795780/how-to-use-mfa-with-aws-cli   * https://stackoverflow.com/questions/34795780/how-to-use-mfa-with-aws-cli
   * https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_use-resources.html   * https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_use-resources.html
  
wiki/aws_cli_2fa.1729686895.txt.gz · Last modified: 2024/10/23 14:34 by antisa

Except where otherwise noted, content on this wiki is licensed under the following license: CC0 1.0 Universal
CC0 1.0 Universal Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki