aws-sts-get-session-token script
Jump to navigation
Jump to search
Contents
Usage
aws-sts-get-session-token yourusername your_token
Code
#/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
See also
aws sts get-session-token
- AWS STS
(sts:)
,aws sts
[get-session-token
|get-caller-identity
|assume-role | assume-role-with-web-identity | 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: