CloudFormation, passing a List parameter as a

2019-07-24 18:08发布

问题:

How can I pass a parameters of type List<AWS::EC2::Subnet::Id> as a comma separated string?

I have the following template:

{
  "AWSTemplateFormatVersion": "2010-09-09",

  "Parameters": {
    "PrivateSubnets": {
      "Description": "The private subnets in which Beanstalk EC2 instances will created",
      "Type": "List<AWS::EC2::Subnet::Id>"
    },
    "PublicSubnets": {
      "Description": "The public subnets in which the Beanstalk ELBs will be created",
      "Type": "List<AWS::EC2::Subnet::Id>"
    }
  },

  "Resources": {
    "MyApp": {
      "Type": "AWS::ElasticBeanstalk::Application",
      "Properties": {
        "ApplicationName": "MyApp",
        "Description": "AWS Elastic Beanstalk Application"
      }
    },

    "ConfigTemplate": {
      "Type": "AWS::ElasticBeanstalk::ConfigurationTemplate",
      "Properties": {
        "ApplicationName": { "Ref": "MyApp" },
        "Description": "Microsite Beanstalk config template",
        "OptionSettings": [
          { "Namespace": "aws:ec2:vpc", "OptionName": "ELBSubnets", "Value": { "Ref": "PublicSubnets" } },
          { "Namespace": "aws:ec2:vpc", "OptionName": "Subnets", "Value": { "Ref": "PrivateSubnets"} }
        ],
        "SolutionStackName": "64bit Amazon Linux 2016.03 v2.1.7 running PHP 5.6"
      }
    }
  }
}

When I attempt to create the stack, I get the following error:

CREATE_FAILED AWS::ElasticBeanstalk::ConfigurationTemplate ConfigTemplate Value of property Value must be of type String

An attempt to use Fn:Join to write the content of the private and public subnets as comma separated strings, e.g.

{ "Namespace": "aws:ec2:vpc", "OptionName": "ELBSubnets", "Value": { "Fn:Join": [",", { "Ref": "PublicSubnets" }]} },
{ "Namespace": "aws:ec2:vpc", "OptionName": "Subnets", "Value": { "Fn:Join": [",", { "Ref": "PrivateSubnets"}]} },

result in

Template validation error: Template Error: Encountered unsupported function: Fn:Join Supported functions are: [Fn::Base64, Fn::GetAtt, Fn::GetAZs, Fn::ImportValue, Fn::Join, Fn::FindInMap, Fn::Select, Ref, Fn::Equals, Fn::If, Fn::Not, Condition, Fn::And, Fn::Or, Fn::Contains, Fn::EachMemberEquals, Fn::EachMemberIn, Fn::ValueOf, Fn::ValueOfAll, Fn::RefAll, Fn::Sub]

回答1:

According to http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/command-options-general.html#command-options-general-ec2vpc you need to provide a comma delimited list. So use Fn::Join (note the two colons)