Difference between revisions of "Aws-sts-get-session-token script"
Jump to navigation
Jump to search
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
{{lowercase}} | {{lowercase}} | ||
+ | == Usage == | ||
+ | aws-sts-get-session-token yourusername your_token | ||
+ | |||
+ | == Code == | ||
#/bin/bash | #/bin/bash | ||
MYUSERNAME=$1 | MYUSERNAME=$1 | ||
Line 6: | Line 10: | ||
function usage() { | function usage() { | ||
− | echo "Usage: $(basename $0) your_username your_token" | + | echo "Usage: $([[basename]] $0) your_username your_token" |
exit 0 | exit 0 | ||
} | } | ||
Line 22: | Line 26: | ||
echo "export [[AWS_SECRET_ACCESS_KEY]]="$AWS_SECRET_ACCESS_KEY"" | echo "export [[AWS_SECRET_ACCESS_KEY]]="$AWS_SECRET_ACCESS_KEY"" | ||
echo "export [[AWS_SESSION_TOKEN]]="$AWS_SESSION_TOKEN"" | echo "export [[AWS_SESSION_TOKEN]]="$AWS_SESSION_TOKEN"" | ||
− | |||
− | |||
− | |||
== Related == | == Related == | ||
Line 34: | Line 35: | ||
== See also == | == See also == | ||
+ | * {{aws sts get-session-token}} | ||
* {{aws sts}} | * {{aws sts}} | ||
* {{aws configure}} | * {{aws configure}} | ||
[[Category:AWS]] | [[Category:AWS]] |
Latest revision as of 04:38, 12 February 2024
Contents
Usage[edit]
aws-sts-get-session-token yourusername your_token
Code[edit]
#/bin/bash MYUSERNAME=$1 MYTOKEN=$2 function usage() { echo "Usage: $(basename $0) your_username your_token" exit 0 } [ -z $1 ] && { usage; } MFA_DEVICE=$(aws iam list-virtual-mfa-devices --output text | grep $MYUSERNAME | grep VIRTUALMFADEVICES | awk '{print $3}') output=$(aws sts get-session-token --serial-number $MFA_DEVICE --token-code $MYTOKEN --output text) AWS_ACCESS_KEY_ID=$(echo $output | awk '{print $2}') AWS_SECRET_ACCESS_KEY=$(echo $output | awk '{print $4}') AWS_SESSION_TOKEN=$(echo $output | awk '{print $NF}') echo "export AWS_ACCESS_KEY_ID="$AWS_ACCESS_KEY_ID"" echo "export AWS_SECRET_ACCESS_KEY="$AWS_SECRET_ACCESS_KEY"" echo "export AWS_SESSION_TOKEN="$AWS_SESSION_TOKEN""
Related[edit]
See also[edit]
aws sts get-session-token
- AWS STS,
aws sts
[get-session-token
|get-caller-identity
|assume-role | assume-role-with-saml | get-access-key-info ]
aws configure [ list-profiles | sso | sso-session | set ]
,~/.aws/config
,.aws/credentials
,mfa_serial
, AWS cli environmental variables:AWS_PROFILE
,AWS_REGION, AWS_DEFAULT_REGION, AWS_SESSION_TOKEN, AWS_ROLE_SESSION_NAME
,.aws/
, AWS functions,--profile, viawsconfig, viawscredentials
Advertising: