[英]How can I create profiles in the AWS CloudShell to access different roles?
AWS 的新CloudShell服務允許我直接在瀏覽器中獲取 CLI session。 在這個 session 中,我正在扮演我目前活躍的角色:
$ aws sts get-caller-identity
{
"UserId": "AROA2MDGRZUIRD434HHAF:johndoe",
"Account": "123456789012",
"Arn": "arn:aws:sts::123456789012:assumed-role/myrole/johndoe"
}
我可以按預期從myrole
擔任另一個角色:
$ aws sts assume-role --role-arn arn:aws:iam::123456789012:role/otherRole --role-session-name mySession123
{
"Credentials": {
"AccessKeyId": "ASIA...",
"SecretAccessKey": "...",
"SessionToken": "...",
"Expiration": "2021-04-28T16:29:55+00:00"
},
"AssumedRoleUser": {
"AssumedRoleId": "AROA...:mySession123",
"Arn": "arn:aws:sts::123456789012:assumed-role/otherRole/mySession123"
}
}
現在我想配置一個 CLI 配置文件以使用otherRole
。 我嘗試了這樣的條目:
[profile otherRole]
role_arn = arn:aws:iam::123456789012:role/otherRole
但這會導致錯誤,因為我必須指定credential_source
或source_profile
。
從具有服務角色的 EC2 實例中,我將設置credential_source=Ec2InstanceMetadata
但這在這里不起作用。 將source_profile
設置為default
也會導致錯誤:
The source profile "default" must have credentials.
如何在 AWS CloudShell 中創建 CLI 配置文件以持久承擔另一個角色?
我發現答案記錄在這里。 CloudShell不使用 EC2 實例,而是在基於 ECS 的容器中運行。 因此將credential_source
設置為EcsContainer
就可以了:
[profile otherRole]
credential_source=EcsContainer
role_arn=arn:aws:iam::123456789012:role/otherRole
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.