Amazon cloudformation 如何在aws cloudformation中共享两个参数之间的允许值

Amazon cloudformation 如何在aws cloudformation中共享两个参数之间的允许值,amazon-cloudformation,Amazon Cloudformation,如何将aws cloudformation模板中一个参数的允许值与另一个参数的允许值共享,因为它们是重复的。请参考下面的代码片段 "Parameters": { "mymasterinstance": { "Description" : "My master instance", "Type": "String", "Default" : "t2.micro", "AllowedValues": ["t2.micro",

如何将aws cloudformation模板中一个参数的允许值与另一个参数的允许值共享,因为它们是重复的。请参考下面的代码片段

  "Parameters": {
    "mymasterinstance": {
        "Description" : "My master instance",
        "Type": "String",
        "Default" : "t2.micro",
        "AllowedValues": ["t2.micro","t2.small","t2.large","t2.xlarge"]
    },
    "myslaveinstance": {
      "Description": "My slave instance",
      "Type" :"String",
      "Default": "t2.micro",
      "AllowedValues" : ["t2.micro","t2.small","t2.large","t2.xlarge"]
    },
  },

我想与myslaveinstance共享mymasterinstance的AllowedValue。任何人都可以在这方面提供帮助。

我不确定我是否理解了您的问题,但我想您希望定义这些实例类型值一次,然后在任何地方使用它。如果这就是问题所在,那么您不能使用普通的yaml/json模板

您可以尝试在纯文本文件中定义配置数据,并使用模板语言(例如,我们使用),在任何需要的地方读取这些值

在我的公司,我们大量使用jinja2来自动化大部分模板。这样做,您可能会得到如下结果:

template.json.jinja

vars.json


注意:jinja是一种python模板语言。根据您的项目性质,您可以选择不同的工具来完成预处理工作。

谢谢您的编辑@danimal。我想知道您在编辑过程中是如何格式化json的。请在代码的上方和下方使用三个倒勾````,然后在缩进中使用空格而不是制表符好的。回到真正的挑战,您能解释一下如何在参数之间共享允许的值吗
"Parameters": {
    "mymasterinstance": {
        "Description" : "My master instance",
        "Type": "String",
        "Default" : "t2.micro",
        "AllowedValues": "{{ instance_allowed_values }}"
    },
    "myslaveinstance": {
      "Description": "My slave instance",
      "Type" :"String",
      "Default": "t2.micro",
      "AllowedValues" : "{{ instance_allowed_values }}"
    },
}
{
  "instance_allowed_values": ["t2.micro","t2.small","t2.large","t2.xlarge"]
}