我正在尝试将 AWS CDK 管道从账户 A(部署账户)部署到账户 B(工作负载账户)。作为我的 CDK 代码的一部分,我正在执行 VPC ID 的查找:
var lambdaVpc = Vpc.FromLookup(this, "VPC", new VpcLookupOptions{
VpcId = Vpc.id
});
但是,当我的管道运行时,我收到以下错误:
Could not assume role in target account using current credentials (which are for account ${DeploymentAccount})
User: arn:aws:sts::${DeploymentAccount}:assumed-role/te-cdk-pipeline-mis-servi-tecdkpipelinemisservicej-UPT0J1RO1RFR/AWSCodeBuild-7bcbd3a0-8159-454b-a886-18f8dd1df58c is not authorized to perform: sts:AssumeRole on resource:
arn:aws:iam::${WorkloadAccount}:role/cdk-hnb659fds-lookup-role-${WorkloadAccount}-ap-southeast-2 .
Please make sure that this role exists in the account. If it doesn't exist, (re)-bootstrap the environment with the right '--trust', using the latest version of the CDK CLI.
我的工作负载帐户角色具有以下政策:
{
"Version": "2008-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::${WorkloadAccount}:root"
},
"Action": "sts:AssumeRole"
},
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::${DeploymentAccount}:root"
},
"Action": "sts:AssumeRole"
}
]
}
据我所知,这应该允许部署帐户承担并使用此角色。所有这些角色/权限都是由 CDK/引导过程创建的。
我尝试删除管道并重新部署(以便 CDK 重新创建所有 IAM 角色/策略),但到目前为止没有成功。
有人遇到过这种情况吗?
最佳答案
建议的做法是在具有执行查找所需权限的本地计算机上合成应用程序一次,然后将 cdk.context.json 提交到 git,这将使管道使用缓存的值并且不需要执行任何查找。
这实现的是使您的 CDK 代码具有确定性的最佳实践 - 它应该始终合成相同的模板,并确保您只在实现此目的后才进行网络调用。
关于amazon-web-services - 无法承担查找角色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71836645/