向Cloudformation模板的参数文件添加列表

时间:2019-07-03 17:14:17

标签: json amazon-web-services parameters yaml amazon-cloudformation

我有一个cloudformation模板,在其中发送JSON参数文件。这不是一个真正的问题,因为我的参数文件以前看起来像这样:

[
    "InstanceType=t2.medium",
    "AmiStack=amilookup-stack"
]

但是,我想向参数文件添加一个列表,如下所示:

[
    "InstanceType=t2.medium",
    "AmiStack=amilookup-stack",
    [
        "CertificateArn1=arn:aws:acm:us-east-1:xxx",
        "CertificateArn2=arn:aws:acm:us-east-1:xxy",
    ]
]

在我的参数json文件中表达此信息的最佳方法是什么,以及如何在cloudformation模板本身中表达此信息?enter code here

1 个答案:

答案 0 :(得分:1)

这是known problem,带有Cloudformation。您可以使用comma demlimited list作为参数类型。

Cloudformation模板(test.json)

 {
  "AWSTemplateFormatVersion": "2010-09-09",
  "Parameters": {
    "Name": {
      "Type": "String",
      "Description": "SubnetGroup Name"
    },
    "Subnets": {
      "Type": "CommaDelimitedList",
      "Description": "The list of SubnetIds in your Virtual Private Cloud (VPC)"
    }
  },
  "Resources": {
    "myDBSubnetGroup": {
      "Type": "AWS::RDS::DBSubnetGroup",
      "Properties": {
        "DBSubnetGroupDescription": "description",
        "DBSubnetGroupName": {
          "Ref": "Name"
        },
        "SubnetIds": {
          "Ref": "Subnets"
        }
      }
    }
  }
}

Parameter.json

[
  {
    "ParameterKey": "Name",
    "ParameterValue": "testName"
  },
  {
    "ParameterKey": "Subnets",
    "ParameterValue": "subnet-abcdefg,subnet-abcdef1,subnet-abcdef2"
  }
]


aws cloudformation create-stack --stack-name testStack --template-body file://test.json --parameters file://parameter.json --profile yourawsprofile