0

AWS的新CloudShell服务允许我直接在浏览器中获取 CLI 会话。在本次会议中,我以我目前的活跃角色行事:

$ 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

但这会导致错误,因为我必须指定 acredential_source或 a source_profile

从具有我要设置的服务角色的 EC2 实例,credential_source=Ec2InstanceMetadata但这在这里不起作用。设置source_profiledefault也会导致错误:

The source profile "default" must have credentials.

如何在 AWS CloudShell 中创建 CLI 配置文件以持久承担另一个角色?

4

1 回答 1

0

我发现答案记录在这里CloudShell不使用 EC2 实例,而是在基于 ECS 的容器中运行。因此设置credential_sourcetoEcsContainer就可以了:

[profile otherRole]
credential_source=EcsContainer
role_arn=arn:aws:iam::123456789012:role/otherRole
于 2021-04-29T12:47:51.760 回答