无法承担查找角色

CJW*_*CJW 2 amazon-web-services amazon-iam aws-cdk

我正在尝试将 AWS CDK 管道从账户 A(部署账户)部署到账户 B(工作负载账户)。作为我的 CDK 代码的一部分,我正在执行 VPC ID 的查找:

      var lambdaVpc = Vpc.FromLookup(this, "VPC", new VpcLookupOptions{ 
        VpcId = Vpc.id
      });
Run Code Online (Sandbox Code Playgroud)

但是,当我的管道运行时,出现以下错误:

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.
Run Code Online (Sandbox Code Playgroud)

我的工作负载帐户角色具有以下策略:

{
    "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"
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

据我所知,这应该允许部署帐户承担并使用此角色。所有这些角色/权限都是由 CDK/引导过程创建的。

我尝试删除管道并重新部署(以便 CDK 重新创建所有 IAM 角色/策略),但到目前为止还没有成功。

有人遇到过这个吗?

gsh*_*hka 5

推荐的做法是在具有执行查找所需权限的本地计算机上合成一次应用程序,然后提交cdk.context.json到 git,这将使管道使用缓存的值而无需执行任何查找。

这实现的是使 CDK 代码具有确定性的最佳实践 - 它应该始终合成相同的模板,并确保仅在实现此目的后才进行网络调用。