jsonamazon-web-servicesaws-cloudformationaws-codepipeline

AWS CloudFormation: "Parameter [subnetIds] is invalid"


I have a AWS CodePipeline to deploy a stack in CloudFormation using a YAML template as well as a template configuration JSON file.

Relevant Template Snippet:

AWSTemplateFormatVersion: '2010-09-09'
...
Parameters:
  subnetIds:
    Type: List<AWS::EC2::Subnet::Id>
...

Relevant Configuration File Snippet:

{
    "Parameters": {
      ...
      "subnetIds": [
        "subnet-a",
        "subnet-b",
        "subnet-c"
      ]
    },
    ...
}

For some reason the Deploy stage (CloudFormation) keeps failing with Parameter [subnetIds] is invalid, so my question is how do I pass a list of subnetIds to the template from the configuration file?


Solution

  • It is explained here in the docs about list data types, such as:

    List<AWS::EC2::Subnet::Id>

    An array of subnet IDs, such as subnet-123a351e, subnet-456b351e.

    That is to say, all List types in CloudFormation are also comma-separated strings.

    Since you are using a CodePipeline Template Configuration File, you will have something like:

    {
      "Parameters": {
        "subnetIds": "subnet-a,subnet-b,subnet-c"
      }
    }