简体   繁体   English

带有可在代码中使用的参数的 AWS CDK 配置文件

[英]AWS CDK Configuration File With Parameters That Can Be Used In Code

I'm using the AWS CDK, and currently I have parameters that I want to be able to change in a sort of configuration file.我正在使用 AWS CDK,目前我有一些我希望能够在某种配置文件中更改的参数。 I can't use the --parameters argument from the command line because A) I need to use the parameter values in the actual code (mainly in function calls/if statements) and B) There are enough parameters that it would be annoying to type every single one into the command line.我不能从命令行使用 --parameters 参数,因为 A)我需要在实际代码中使用参数值(主要是在 function 调用/if 语句中)和 B)有足够的参数,这会很烦人在命令行中键入每一个。

Is there some type of way I can just define a JSON or YAML file that the user can edit, and then use those values directly in the cdk_stack.py file?是否有某种方法可以定义用户可以编辑的 JSON 或 YAML 文件,然后直接在 cdk_stack.py 文件中使用这些值?

This question doesn't exactly need an answer.这个问题并不完全需要答案。 However, you can create a .json file and then simply add a key named "params" and the value as a list or whatever you want to name it.但是,您可以创建一个.json文件,然后简单地添加一个名为"params"的键和作为列表的值或任何您想要命名的值。 There, the user can enter the parameter names, then using the open() function and the json module you can read the file using python.在那里,用户可以输入参数名称,然后使用open() function 和json模块,您可以使用 python 读取文件。

AWS CDK Context is recommended way to do that:推荐使用 AWS CDK 上下文来执行此操作:

https://docs.aws.amazon.com/cdk/v2/guide/context.html https://docs.aws.amazon.com/cdk/v2/guide/context.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM