Cloud formation choosing multiple subnets

Previously to populate a number of subnet IDs into a parameter for an AWS Cloudformation script, you had to either pre-populate your CF template or type them in when launching the CF stack. I was very excited to see the new Parameter type : “List” which could be used to for a drop-down list for choosing multiple subnet IDs as part of launching your CF stack from a template. However it wouldn’t work for me when creating AWS  Elastic Beanstalk environments and gave an error that it required type string.

This is because for the configuration option in AWS Elastic Beanstalk (EB) for option_name : Subnets under Namespace: aws:ec2:vpc; the value is expected as a single comma-delimited string of subnet IDs (for example, “subnet-11111111,subnet-22222222”). As shown in the documentation of the configuration options in EB here: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/command-options.html#command-options-general-ec2vpc.

The Parameter type : “List” will give the list of subnet-ids in output (an array of subnet IDs, such as [subnet-123a351e, subnet-456b351e] ), whereas the EB option value is expected to be of type : “string”.

You can however use Intrinsic function “Fn:Join” to join a set of values into a single string with a delimiter. Refer to http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-join.html for more details on Fn:Join.

Thus you can successfully use:
“Value” : {“Fn::Join” : [ “,”, { “Ref” : “Subnets”} ] }
Instead of:
“Value” : { “Ref” : “Subnets”}