即使在使用新存储桶和限定符重新引导后,AWS CDK 仍会引用旧的引导限定符

问题描述 投票:0回答:1

我正在使用 AWS CDK 部署堆栈。我已使用新的 S3 存储桶和新的限定符 (sandbuck2) 成功引导环境,但在部署过程中,CDK 不断引用旧的引导限定符 (hnb659fds),并失败并出现以下错误:

SSM parameter /cdk-bootstrap/hnb659fds/version not found. Has the environment been bootstrapped? Please run 'cdk bootstrap' (see https://docs.aws.amazon.com/cdk/latest/guide/bootstrapping.html)

旧的限定符 (hnb659fds) 在之前的引导程序中使用过,但我后来使用新的存储桶和限定符 (sandbuck2) 引导了环境。尽管确认新限定符的新 SSM 参数存在,CDK 仍然引用旧的 SSM 参数。

1.使用以下命令引导新环境:

cdk bootstrap --bootstrap-bucket-name cdk-bootstrap-assets-975049968143-ap-south-1-sandbucket2 \
--cloudformation-execution-policies arn:aws:iam::aws:policy/AdministratorAccess \
--qualifier sandbuck2 \
aws://975049968143/ap-south-1 --force

2.使用以下方法清除CDK上下文:

cdk context --clear

3.删除项目目录下的cdk.context.json文件。

4.检查SSM参数: 新的 SSM 参数 /cdk-bootstrap/sandbuck2/version 存在。 参数存储中没有 /cdk-bootstrap/hnb659fds/version 。

5.在我的整个项目中搜索任何对 hnb659fds 的硬编码引用,并将其替换为 sandbuck2。代码中不再保留对旧限定符的引用。

6.尝试在代码中添加带有存储桶名称和限定符的合成器

7.尝试重新引导它说se存储桶已经存在并且失败

amazon-web-services amazon-s3 aws-cloudformation aws-cdk aws-ssm
1个回答
0
投票

hnb659fds
是默认限定符。为了让您的 CDK 代码知道您已使用不同的代码进行引导,您需要将
DefaultSynthesizer
的自定义实例传递给堆栈,并使用 qualifier
 属性将 
synthesizer
 设置为字符串,或将 
@aws-cdk/core:bootstrapQualifier
上下文变量设置为您的自定义限定符。

选项 1:

const myCustomSynthesizer = new new DefaultStackSynthesizer({
    qualifier: 'sandbuck2',
});

new Stack(app, 'MyStack', {
    synthesizer: myCustomSynthesizer
});

选项2:

将以下内容添加到您的

cdk.json
对象中:

"context": {
    "@aws-cdk/core:bootstrapQualifier": "sandbuck2",
}
© www.soinside.com 2019 - 2024. All rights reserved.