amazon-web-services - 无法承担查找角色

标签 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
      });

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

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/

相关文章:

python - AWS CDK 如何在 IAM 策略中包含委托(delegate)人?

javascript - AWS cognito userpools JavaScript SDK 获取用户的保单文件

amazon-web-services - 在 CDK 中配置 lambda 并发

AWS-CDK 错误 : There are no 'Public' subnets in this VPC. 使用不同的 VPC 子网选择

amazon-web-services - 如何在 2 个不同的 cloudformation 模板中创建 S3 和触发的 lambda

android - Cognito 用户池 : How to refresh Access Token Android

amazon-web-services - 如何增加 AWS Fargate 容器中的磁盘空间?

amazon-web-services - 从安全组自身继承

python-3.x - 由 AWS 托管 key 加密的 AWS 跨账户 S3 PutObject 中的访问被拒绝问题

amazon-web-services - AWS CDK -- 找不到模块 '@aws-cdk/aws-ec2'