Passing parameters of type List<AWS::EC2::Subnet::Id> to nested CloudFormation template
In YAML you need to "split" the Subnets by using Select. For example with two subnets :
!Join [",", [!Select [0, !Ref Subnets], !Select [1, !Ref Subnets]]]
Successfully built in YAML using the following excerpt:
Parameters:
pSubnetIDs:
Description: The array of Subnet IDs for the Subnet group
Type: List<AWS::EC2::Subnet::Id>
Resources:
rDBSubnetGroup:
Type: "AWS::RDS::DBSubnetGroup"
Properties:
DBSubnetGroupDescription: The subnet group for the RDS instance
SubnetIds: !Ref pSubnetIDs
I tried a bunch of variations of !Join and !Ref with no success. Turns out it is just straightforward !Ref of the list.
Lists can be converted into Strings and vice versa. So the working invocation is
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Parameters": {
"ChildTemplate": {
"Type": "String",
"Default": "https://s3.eu-central-1.amazonaws.com/cf-templates-xxxxxxxxxxx-eu-central-1/sample_child.template"
},
"ELBSubnetList" : {
"Type" : "List<AWS::EC2::Subnet::Id>",
"Description" : "Subnet List for Elastic Loadbalancer"
},
"ELBSecurityGroupList": {
"Type": "List<AWS::EC2::SecurityGroup::Id>",
"Description": "Security Group List for Elastic Loadbalancer"
}
},
"Resources": {
"Child": {
"Type": "AWS::CloudFormation::Stack",
"Properties": {
"TemplateURL": { "Ref": "ChildTemplate" },
"Parameters": {
"ELBSubnetList": {"Fn::Join": [",", { "Ref": "ELBSubnetList" }]},
"ELBSecurityGroupList": {"Fn::Join": [",", { "Ref": "ELBSecurityGroupList" }]}
}
}
}
}
}