AWS CDK 新合成器版本

AWS CDK new synthesizer version

我已经为新的“StyleStackSynthesis”引导了 CDKToolKit 堆栈 我将此字段添加到 cdk.json

"@aws-cdk/core:newStyleStackSynthesis": "true"

此 CDKToolKit 堆栈已成功部署到 AWS。 我用过这个命令

cdk bootstrap  --toolkit-stack-name custom-cdktoolkit

但现在我尝试使用 CDKToolKit 堆栈来部署我的 CDK 应用程序堆栈,我收到了这条消息

 Error: Could not assume role in target account (did you bootstrap the environment with the right '--trust's?)

我用这个命令

cdk deploy --toolkit-stack-name custom-cdktoolkit

我也已将其添加到 cdk 应用程序堆栈

 "@aws-cdk/core:newStyleStackSynthesis": "true"

我应该添加一些额外的配置等吗?

我刚刚在一个全新且未受影响的帐户上重播了您 post 的所有内容。

我正在使用 AWS CDK 版本:1.70.0(最新于 2020/10/28)

  1. cdk.json内添加"@aws-cdk/core:newStyleStackSynthesis": "true"
  2. 运行cdk bootstrap --toolkit-stack-name custom-cdktoolkit。这是您在 post.
  3. 中提供的命令
cdk bootstrap --toolkit-stack-name custom-cdktoolkit

'@aws-cdk/core:newStyleStackSynthesis' context set, using new-style bootstrapping
 ⏳  Bootstrapping environment aws://xxxxxx/us-east-1...
 ❌  Environment aws://xxxxxx/us-east-1 failed bootstrapping: Error: Please pass '--cloudformation-execution-policies' to specify deployment permissions. Try a managed policy of the form 'arn:aws:iam::aws:policy/<PolicyName>'.

所以,我这边已经无法重现了。

由于缺少更多信息,接下来的每一步现在都是自由泳。

  1. 根据需要添加cf-execution-policies:
cdk bootstrap \
--toolkit-stack-name custom-cdktoolkit \
--cloudformation-execution-policies arn:aws:iam::aws:policy/AdministratorAccess

'@aws-cdk/core:newStyleStackSynthesis' context set, using new-style bootstrapping
 ⏳  Bootstrapping environment aws://xxxxx/us-east-1...
Trusted accounts:   (none)
Execution policies: arn:aws:iam::aws:policy/AdministratorAccess
custom-cdktoolkit: creating CloudFormation changeset...
[██████████████████████████████████████████████████████████] (11/11)
 ✅  Environment aws://xxxxx/us-east-1 bootstrapped.
  1. 好的,让我们快速看一下示例堆栈(没有您在评论中所说的任何 cross-account 访问权限):
// file: lib/cdk-playground-stack.ts
import * as cdk from "@aws-cdk/core";
import * as s3 from "@aws-cdk/aws-s3";
export class CdkPlaygroundStack extends cdk.Stack {
  constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    new s3.Bucket(this, "id", {
      accessControl: s3.BucketAccessControl.PRIVATE,
      encryption: s3.BucketEncryption.S3_MANAGED,
      versioned: false,
      blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL,
    });
  }
}
// file: app/app.ts

#!/usr/bin/env node
import 'source-map-support/register';
import * as cdk from '@aws-cdk/core';
import { CdkPlaygroundStack } from '../lib/cdk-playground-stack';

const app = new cdk.App();
// no cross-account environment arguments (like account) passed to the stack!
new CdkPlaygroundStack(app, 'CdkPlaygroundStack');
  1. 通过您提供的命令部署它(由于 non-default cdk-bootstrap-name)
cdk deploy --toolkit-stack-name custom-cdktoolkit

CdkPlaygroundStack: deploying...
[0%] start: Publishing dbfc18c149132627081b768fbbfc4bc345aeba4259514174fcd302d8b3926a90:current_account-current_region
[100%] success: Published dbfc18c149132627081b768fbbfc4bc345aeba4259514174fcd302d8b3926a90:current_account-current_region
CdkPlaygroundStack: creating CloudFormation changeset...
[██████████████████████████████████████████████████████████] (3/3)

 ✅  CdkPlaygroundStack

Stack ARN:
arn:aws:cloudformation:us-east-1:xxxxxxx:stack/CdkPlaygroundStack/9b8d4460-1940-11eb-abd9-0e794c84352f

如您所见,没有任何冲突,并且根据您提供的信息,很难验证正在发生的事情。

你能做什么?

  • 更新到当前版本的CDK
  • 检查您的 Stack 创建,如果确实没有 argument/props 根据您在 AWS profile/environment 变量中使用的另一个帐户传递。 Cross-Account 部署需要特定的 bootstrap 设置,所以我专门询问了这一点。
  • 删除 bootstrapped CloudFormation 堆栈
  • 完全重现我所做的

以下方法对我有用,尤其是第二种,我们拥有跨账户信任和承担角色的场景。

在配置管道之前,您必须 bootstrap 要在其中创建它的环境。如果要将应用程序部署到不同的环境,您还必须 bootstrap 这些和请务必添加信任关系。

到 bootstrap 供应管道的环境:

$ env CDK_NEW_BOOTSTRAP=1 npx cdk bootstrap
[--profile admin-profile-1]
--cloudformation-execution-policies arn:aws:iam::aws:policy/AdministratorAccess
aws://111111111111/us-east-1

到 bootstrap 用于部署 CDK 应用程序的不同环境,以使用帐户 111111111111 中的管道:

$ env CDK_NEW_BOOTSTRAP=1 npx cdk bootstrap
[--profile admin-profile-2]
--cloudformation-execution-policies arn:aws:iam::aws:policy/AdministratorAccess
--信任 11111111111
aws://222222222222/us-east-2