wiki:aws_cli_2fa
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| wiki:aws_cli_2fa [2024/10/16 12:18] – created antisa | wiki:aws_cli_2fa [2024/12/29 14:05] (current) – [AWS CLI with 2FA] add aws-vault tool link antisa | ||
|---|---|---|---|
| Line 13: | Line 13: | ||
| The // | The // | ||
| - | Then copy paste all of the fields in // | + | Then copy paste all of the fields in // |
| Example: | Example: | ||
| Line 44: | Line 44: | ||
| < | < | ||
| - | [myprofile] | + | [myprofile-session] |
| aws_access_key_id = xxxxxxxxxxxxxxxxxxx | aws_access_key_id = xxxxxxxxxxxxxxxxxxx | ||
| aws_secret_access_key = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | aws_secret_access_key = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | ||
| Line 51: | Line 51: | ||
| </ | </ | ||
| + | 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. | ||
| + | . ~/ | ||
| + | |||
| + | Or just use [[https:// | ||
| + | |||
| + | <file bash aws_get_session.sh> | ||
| + | #!/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. | ||
| + | # . ~/ | ||
| + | |||
| + | # debug | ||
| + | # set -x | ||
| + | |||
| + | if [ " | ||
| + | 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 | ||
| + | |||
| + | # colors | ||
| + | On_Yellow=' | ||
| + | On_White=' | ||
| + | NC=' | ||
| + | |||
| + | echo " | ||
| + | sed -i '/ | ||
| + | |||
| + | echo " | ||
| + | # use existing profile | ||
| + | KST=$(AWS_PROFILE=myprofile aws sts get-session-token --serial-number arn: | ||
| + | cat << EOF >> ~/ | ||
| + | [myprofile-session] | ||
| + | aws_access_key_id = $(echo " | ||
| + | aws_secret_access_key = $(echo " | ||
| + | aws_session_token = $(echo " | ||
| + | |||
| + | EOF | ||
| + | |||
| + | # below export will only work when sourcing this script | ||
| + | export AWS_PROFILE=myprofile-session | ||
| + | echo -e " | ||
| + | |||
| + | </ | ||
| ====== Tested on ====== | ====== Tested on ====== | ||
| * aws-cli/ | * aws-cli/ | ||
| ====== See also ====== | ====== See also ====== | ||
| + | * [[wiki: | ||
| ====== References ====== | ====== References ====== | ||
| * https:// | * https:// | ||
| * https:// | * https:// | ||
wiki/aws_cli_2fa.1729081101.txt.gz · Last modified: by antisa
