[英]Adding instances behind multiple LoadBalancers in CloudFormation?
I am trying to figure out a way to add a ec2 node to two load balancers, but am not finding a sane way to do it. 我正在尝试找出一种将ec2节点添加到两个负载均衡器的方法,但是没有找到一种明智的方法来做到这一点。 I would think that the below code would allow me to do this, but am not getting my expected results 我认为下面的代码将允许我执行此操作,但未获得预期的结果
Please note that this code is HIGHLY stripped down to just show the LB portion. 请注意,此代码已高度精简以仅显示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"
}]
}
}
}
}
I would expect to see a list which I can add multiple LBs to, but I am instead seeing a normal input box (string) 我希望看到一个可以添加多个LB的列表,但我看到的是一个普通的输入框(字符串)
Adding in images with some firebug hackery.... 添加带有萤火虫黑客的图像。
UPDATE 更新
After fudging with Cloud Designer, I believe that "Type": "List<AWS::EC2::LoadBalancers::LoadBalancerNames>"
is incorrect and should really be "Type": "List<AWS::ElasticLoadBalancing::LoadBalancer>"
在使用Cloud Designer进行伪造之后,我认为"Type": "List<AWS::EC2::LoadBalancers::LoadBalancerNames>"
是不正确的,并且实际上应该是"Type": "List<AWS::ElasticLoadBalancing::LoadBalancer>"
This still does not propagate as a list though 虽然这仍然不会传播为列表
Figured it out. 弄清楚了。 You will need multiple references. 您将需要多个参考。 And the reason is because the "LoadBalancerNames"
key can take multiple references, like so: "LoadBalancerNames": { "Foo", "Bar" }
原因是因为"LoadBalancerNames"
键可以采用多个引用,例如: "LoadBalancerNames": { "Foo", "Bar" }
Really hope this helps someone else as it had me scratching my head for days :) 真希望这能对别人有所帮助,因为它让我me了好几天的头:)
{
................
"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"
}],
..........
}
This won't give you the UI you were looking for, but it will allow you to specify multiple load balancer names in a single parameter. 这不会为您提供所需的用户界面,但是它将允许您在单个参数中指定多个负载均衡器名称。
Use CommaDelimitedList
as the parameter type. 使用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"
}
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.