簡體   English   中英

如何在 AWS CloudShell 中創建配置文件以訪問不同的角色?

[英]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_sourcesource_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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM