如何在 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_source
或 source_profile
。
从具有服务角色的 EC2 实例我会设置 credential_source=Ec2InstanceMetadata
但这在这里不起作用。
将 source_profile
设置为 default
也会导致错误:
The source profile "default" must have credentials.
如何在 AWS CloudShell 中创建一个 CLI-profile 以持续承担另一个角色?
我找到了要记录的答案 here。
CloudShell 不使用 EC2 实例,而是 运行 在基于 ECS 的容器中。因此将 credential_source
设置为 EcsContainer
就可以了:
[profile otherRole]
credential_source=EcsContainer
role_arn=arn:aws:iam::123456789012:role/otherRole
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-profile 以持续承担另一个角色?
我找到了要记录的答案 here。
CloudShell 不使用 EC2 实例,而是 运行 在基于 ECS 的容器中。因此将 credential_source
设置为 EcsContainer
就可以了:
[profile otherRole]
credential_source=EcsContainer
role_arn=arn:aws:iam::123456789012:role/otherRole