我试图找到一种方法将ec2节点添加到两个负载均衡器,但我没有找到一个理智的方法来做到这一点。我认为下面的代码可以让我这样做,但是没有得到我预期的结果
请注意,此代码被高度剥离以仅显示LB部分。
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": " App Demo / Jd / 01042016",
"Parameters": {
"LoadBalancers": {
"Description": "Please refer the LoadBalancerNames which you want the instances to be registered to",
"Type": "List<AWS::EC2::LoadBalancers::LoadBalancerNames>",
"Default": "web-app-demo-ext,web-api-demo-ext"
}
},
"Resources": {
"AppAutoScalingGroup": {
"Type": "AWS::AutoScaling::AutoScalingGroup",
"Properties": {
"AvailabilityZones": {
"Ref": "AZs"
},
"LoadBalancerNames": [{
"Ref": "LoadBalancers"
}]
}
}
}
}
我希望看到一个列表,我可以添加多个LB,但我却看到了一个正常的输入框(字符串)
添加一些萤火虫hackery图像....
更新
在使用Cloud Designer捏造后,我认为"Type": "List<AWS::EC2::LoadBalancers::LoadBalancerNames>"
不正确,应该是"Type": "List<AWS::ElasticLoadBalancing::LoadBalancer>"
这仍然不会作为列表传播
答案 0 :(得分:1)
想出来。您将需要多个参考。原因是因为"LoadBalancerNames"
键可以采用多个引用,如:"LoadBalancerNames": { "Foo", "Bar" }
真的希望这可以帮助别人,因为它让我头疼了好几天:)
{
................
"Parameters": {
.......
"LoadBalancerApp": {
"Description": "Please refer the LoadBalancerNames (APP) which you want the instances to be registered to",
"Type": "String",
"Default": "web-app-demo-ext"
},
"LoadBalancerApi": {
"Description": "Please refer the LoadBalancerNames (API) which you want the instances to be registered to",
"Type": "String",
"Default": "web-api-demo-ext"
},
.......
},
"Resources": {
........
"AppnameAutoScalingGroup": {
"Type": "AWS::AutoScaling::AutoScalingGroup",
"Properties": {
"AvailabilityZones": {
"Ref": "AZs"
},
"LaunchConfigurationName": {
"Ref": "AppnameLaunchConfig"
},
"LoadBalancerNames": [{
"Ref": "LoadBalancerApp"
}, {
"Ref": "LoadBalancerApi"
}],
..........
}
答案 1 :(得分:1)
这不会为您提供所需的UI,但它允许您在单个参数中指定多个负载均衡器名称。
使用CommaDelimitedList
作为参数类型。
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": " App Demo / Jd / 01042016",
"Parameters": {
"LoadBalancers": {
"Description": "Please refer the LoadBalancerNames which you want the instances to be registered to",
"Type": "CommaDelimitedList",
"Default": "web-app-demo-ext,web-api-demo-ext"
}
},
"Resources": {
"AppAutoScalingGroup": {
"Type": "AWS::AutoScaling::AutoScalingGroup",
"Properties": {
"AvailabilityZones": {
"Ref": "AZs"
},
"LoadBalancerNames": {
"Ref": "LoadBalancers"
}
}
}
}
}