【问题标题】:Adding instances behind multiple LoadBalancers in CloudFormation?在 CloudFormation 中的多个 LoadBalancer 后面添加实例?
【发布时间】:2016-01-06 04:07:23
【问题描述】:

我正在尝试找出一种将 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 的列表,但我看到的是一个普通的输入框(字符串)

添加带有一些萤火虫骇客的图像....

预期结果

实际发生的事情

更新

在和Cloud Designer混过之后,我认为"Type": "List&lt;AWS::EC2::LoadBalancers::LoadBalancerNames&gt;"是不正确的,应该是"Type": "List&lt;AWS::ElasticLoadBalancing::LoadBalancer&gt;"

这仍然不会作为列表传播

【问题讨论】:

  • 尝试从您的参数中删除“默认”。
  • @MattHouser 没用
  • 你的“预期结果”从何而来?
  • @MattHouser 特别是我为 AZs 修改的这个 sn-p 可以工作 pastebin.ca/3318004

标签: amazon-web-services amazon-elb amazon-cloudformation


【解决方案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"
        }
      }
    }
  }
}

【讨论】:

    【解决方案2】:

    想通了。您将需要多个参考。原因是"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?
    猜你喜欢
    • 1970-01-01
    • 2011-10-05
    • 2013-12-23
    • 1970-01-01
    • 2019-03-29
    • 2019-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多