2014 年亚马逊从AWS_SECURITY_TOKEN
到AWS_SESSION_TOKEN
,你也应该支持后者。许多项目仍然要么设置要么检查两者,但已经5年了。我想我们可以放手。
该aws sts assume-role
命令只返回SessionToken
,我只在我编写的代码中支持它。
以下是使用 aws cli 的示例:
function mfa_serial(){
aws configure get --profile=$1 mfa_serial
}
function role_arn(){
aws configure get --profile=$1 role_arn
}
function assrole(){
aws sts assume-role \
--role-arn "$(role_arn $1)" \
--serial-number "$(mfa_serial $1)" \
--token-code "$(mfa)" \
--role-session-name "$( ( id -un; date +-%Y-%m-%d+%H.%M.%S ) | tr -d '\n' )"
}
assrole development
这是输出:
{
"AssumedRoleUser": {
"AssumedRoleId": "AROAIWL33TL33TL33TL33:brunobronosky",
"Arn": "arn:aws:sts::485548554855:assumed-role/allow-full-access-from-other-accounts/brunobronosky"
},
"Credentials": {
"SecretAccessKey": "L33TL33TL33TL33TL33TL33TL33TL33TL33TL33T",
"SessionToken": "L33TL33TL33TEI///////////L33TL33TL33TL33TL33TL33TL33TL33TL33TL33TL33TL33Tm9/TL33TL33TL33TL33T/TL33TL33TL33TL33TL33TL33TL33TL33TL33TL33Tz9/TL33TL33TL33TL33TL33TL33TL33TL33TL33TL33TL33TL33TS/TL33TL33TL33TL33TL33TL33TL33TL33TL33T/TL33TL33TL33TL33TL33TL33TL33TL33TL33TL33TL33TL33TL33TL33TL33TL33TL33TL33TL33TL33TL33TL33Tos/TL33TL33TL33TL33TL33TL33TL33T/A==",
"Expiration": "2019-11-01T00:00:00Z",
"AccessKeyId": "ASIAL33TL33TL33TL33T"
}
}