在 CloudFormation 中的多个 LoadBalancer 后面添加实例?
Adding instances behind multiple LoadBalancers in CloudFormation?
我正在尝试找出一种将 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 的列表,但我看到的是一个普通的输入框(字符串)
添加带有一些 firebug hackery 的图像....
预期结果
实际发生了什么
更新
经过 Cloud Designer 的胡编乱造,我认为 "Type": "List<AWS::EC2::LoadBalancers::LoadBalancerNames>"
是不正确的,应该是 "Type": "List<AWS::ElasticLoadBalancing::LoadBalancer>"
虽然这仍然没有作为列表传播
想通了。您将需要多个参考。原因是 "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"
}],
..........
}
这不会为您提供您正在寻找的 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"
}
}
}
}
}
我正在尝试找出一种将 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 的列表,但我看到的是一个普通的输入框(字符串)
添加带有一些 firebug hackery 的图像....
预期结果
实际发生了什么
更新
经过 Cloud Designer 的胡编乱造,我认为 "Type": "List<AWS::EC2::LoadBalancers::LoadBalancerNames>"
是不正确的,应该是 "Type": "List<AWS::ElasticLoadBalancing::LoadBalancer>"
虽然这仍然没有作为列表传播
想通了。您将需要多个参考。原因是 "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"
}],
..........
}
这不会为您提供您正在寻找的 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"
}
}
}
}
}