【发布时间】:2020-06-28 18:43:02
【问题描述】:
是否可以多次将 CDK 应用部署到同一个帐户?我想运行synth 一次,然后针对该合成模板运行cdk deploy 多次。
我可以看到 CDK 最近的1.28.0 release 允许将 CloudFormation 参数传递到deploy command(通过#1237)。这意味着我可以参数化堆栈的内容,但我不知道如何更改应用程序本身的名称/ID。
例如,这是一个简单的应用程序:
public class ExampleApp {
public static void main(final String[] args) {
App app = new App();
new ExampleStack(app, "ExampleStack");
app.synth();
}
}
这是一个简单的无操作堆栈:
public class ExampleStack extends Stack {
public ExampleStack(final Construct scope, final String id) {
this(scope, id, null);
}
public ExampleStack(final Construct scope, final String id, final StackProps props) {
super(scope, id, props);
CfnParameter someVar = CfnParameter.Builder.create(this, "SomeVar")
.description("Some variable that can be passed in at deploy-time.")
.type("String")
.build();
// rest of stack here
}
}
我可以运行cdk synth并将模板输出到某处,然后运行
cdk --app path/to/cdk.out deploy ExampleStack --parameters "ExampleStack:SomeVar=SomeValue"
并且参数将在部署时传递到堆栈中。
但是,我看不到如何使用不同的名称(或 ID)多次部署应用程序。这可能吗?
我为什么要这样做而不是多次运行 synth 的背景是因为出于合规性原因,我需要一个工件 - cdk.out 目录 - 然后多次部署它。为此,我不能使用基于多次运行 synth 的答案。
【问题讨论】:
-
您是否尝试过添加循环?
for (String name : myListOfNames) new ExampleStack(app, name); -
或者只是用不同的 id 构造两次? (没有必要使用循环)
-
不,不幸的是,这仍然会在
synth时间定义堆栈,而不是deploy时间。在运行synth时,我不知道我需要多少堆栈实例。 -
抱歉。我误解了多次运行 deploy。
标签: amazon-web-services amazon-cloudformation aws-cdk