gpt4 book ai didi

aws-cdk - 传入模板参数

转载 作者:行者123 更新时间:2023-12-04 01:49:51 26 4
gpt4 key购买 nike

我们正在研究在我们的 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 仪表板选项卡中,但没有设置任何值,只有默认值。目前支持吗?如果没有,是否为 future 计划?

最佳答案

随着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"

并且参数将在部署时传递到堆栈中。

关于aws-cdk - 传入模板参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53660503/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com