aws-cdk - 传入模板参数
问题描述
我们正在研究在我们的 CI/CD 管道中使用 aws-cdk。我们需要能够在构建期间将参数传递到模板中,以便它可以生成在部署期间使用的工件。我看到我们可以使用 cdk.json 文件来指定上下文属性,但这实际上并没有将值放入 CloudFormation 模板本身。只是让您可以在代码中访问它们。
我尝试过这样的事情:
const servicenameprop = new PipelinePrerequisitesProps();
servicenameprop.default = 'hello';
servicenameprop.type = 'String';
const serviceNameParameter = new Parameter(this, 'servicename', servicenameprop);
serviceNameParameter.value = new Token(servicename, 'servicename');
这会导致参数出现在 CloudFormation 仪表板选项卡中,但没有设置任何值,只有默认值。目前支持这个吗?如果没有,是否为未来计划?
解决方案
随着 CDK 版本1.28.0的发布,现在可以将 CloudFormation 参数传递给deploy
命令。
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"
并且参数将在部署时传递到堆栈中。
推荐阅读
- java - 提取 3 个子字符串并创建 Animal 对象
- r - 如何将矢量存储在R中的数据框中
- ffmpeg - 如何让 Gstreamer 只返回关键帧?
- git - 如果远程处于特定提交上,是否可以仅 git force push?
- python-3.x - 安装 Tensorflow GPU - 找不到 libcublas.so.9.0,即使它存在且在路径中
- maven - Maven Netbeans 中的实现依赖
- c# - 获取响应广播的设备的 IP 地址
- android - Android Studio 预览版不显示布局
- wpf - WPF 按钮样式不适用于第二个按钮
- typescript - 返回实际类型 Typescript