[英]How to pass list of Refs in CloudFormation JSON?
I used to have a CloudFormation stack which passed VpcId and a List<AWS::EC2::Subnet>
(list of subnets).我曾经有一个 CloudFormation 堆栈,它通过 VpcId 和
List<AWS::EC2::Subnet>
(子网列表)。 but then I decided I actually want my stack to create its own VPC.但后来我决定我真的希望我的堆栈创建自己的 VPC。 So I came up with this:
所以我想出了这个:
{
"PublicSubnetOne": {
"Type": "AWS::EC2::Subnet",
"Properties": {
"VpcId": {"Ref": "VPC"},
"CidrBlock": "10.0.0.0/24",
"AvailabilityZone": {
"Fn::Select": ["0", {"Fn::GetAZs": ""}]
}
}
},
"PublicSubnetTwo": {
"Type": "AWS::EC2::Subnet",
"Properties": {
"VpcId": {"Ref": "VPC"},
"CidrBlock": "10.0.0.0/24",
"AvailabilityZone": {
"Fn::Select": ["1", {"Fn::GetAZs": ""}]
}
}
},
"ApplicationLoadBalancer" : {
"Type" : "AWS::ElasticLoadBalancingV2::LoadBalancer",
"Properties" : {
"Subnets" : { "Ref": "PublicSubnetOne,PublicSubnetTwo"}
}
},
}
This results in the below error:这会导致以下错误:
Unresolved resource dependencies [PublicSubnetOne,PublicSubnetTwo] in the Resources block of the template
模板的 Resources 块中未解决的资源依赖项 [PublicSubnetOne,PublicSubnetTwo]
How to correctly pass a List<>
of Refs to a property?如何正确地将
List<>
的 Refs 传递给属性?
Try this:尝试这个:
{"Ref": "PublicSubnetOne,PublicSubnetTwo"}[{"Ref": "PublicSubnetOne"} , {"Ref": "PublicSubnetTwo"}]
When you say {"Ref": "PublicSubnetOne,PublicSubnetTwo"}
, CloudFormation looks for something with the name verbatim "PublicSubnetOne,PublicSubnetTwo"
.当您说
{"Ref": "PublicSubnetOne,PublicSubnetTwo"}
时,CloudFormation 会逐字查找名称为"PublicSubnetOne,PublicSubnetTwo"
的内容。
You may be confused by this, because it's totally fine to pass a Parameter with --parameter-overrides (from aws cloudformation deploy
) with the value "vpc-someidhere,vpc-someidhere2"
, but it doesn't work that way with refs.您可能对此感到困惑,因为通过 --parameter-overrides (来自
aws cloudformation deploy
)和值"vpc-someidhere,vpc-someidhere2"
传递参数是完全可以的,但它不适用于 refs . I assume CloudFormation formats a comma separated string into a list if a Parameter
's Type
is List<>
如果
Parameter
的Type
是List<>
,我假设 CloudFormation 将逗号分隔的字符串格式化为列表
There's also an answer that has similar keywords that actually recommends joining (Fn::Join) two IDs together, but I got an error like Subnets should be List of String
with that 还有一个答案具有相似的关键字,实际上建议将 (Fn::Join) 两个 ID 连接在一起,但我收到一个错误,例如
Subnets should be List of String
with that
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.