【问题标题】:How to map a LoadBalancer ListenerRule on a specific port using Cloudformation?如何使用 Cloudformation 在特定端口上映射 LoadBalancer ListenerRule?
【发布时间】:2018-10-17 06:31:42
【问题描述】:

我正在使用 CloudFormation 为我的应用程序创建堆栈。

堆栈包含一个现有的 LoadBalancer,我想在其中添加一个新的端口映射规则,用于将请求转发到我的应用程序。

LoadBalancerRule:
    Type: AWS::ElasticLoadBalancingV2::ListenerRule
    Properties:
      Actions:
      - TargetGroupArn: !Ref 'TargetGroup'
        Type: 'forward'
     Conditions:
      - Field: path-pattern
        Values: [!Ref 'PortMapping']
     ListenerArn:
       Fn::ImportValue:
       !Join [':', [!Ref 'StackName']]
         Priority: !Ref 'Priority'

我正在尝试找出正确的条件,以便为我现有的 LoadBalancer 创建一个带有 PortMapping 8080 的 LoadBalancer 侦听器,以创建以下内容:

到目前为止,我无法通过端口号创建映射,只能通过默认端口 80 上的路径模式创建映射。

我查看了有关 Stackoverflow 和 ElasticLoadBalancingV2::ListenerRule 资源页面的问题,但我还没有找到可行的解决方案。 参考:https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-elasticloadbalancingv2-listenerrule.html

我们将不胜感激任何正确方向的帮助!

【问题讨论】:

    标签: amazon-web-services amazon-cloudformation amazon-elb aws-load-balancer


    【解决方案1】:

    以下是 8080 和 443 监听器的示例:

    "ELB": {
      "Type": "AWS::ElasticLoadBalancing::LoadBalancer",
      "Properties": {
        "Subnets": { "Ref": "Subnet" },
        "HealthCheck": {
          "HealthyThreshold": "2",
          "Interval": "10",
          "Target": "HTTP:80/health",
          "Timeout": "8",
          "UnhealthyThreshold": "6"
        },
        "Listeners": [
          {
            "InstancePort": "80",
            "InstanceProtocol": "HTTP",
            "LoadBalancerPort": "8080",
            "Protocol": "HTTP"
          },
          {
            "InstancePort": "80",
            "InstanceProtocol": "HTTP",
            "LoadBalancerPort": "443",
            "Protocol": "HTTPS",
            "SSLCertificateId": {"Ref": "SSLArn"}
          }
        ],
        "SecurityGroups": [
          { "Ref": "ELBSG" }
        ]
      }
    }
    

    对于 yaml:

    ELB: Type: AWS::ElasticLoadBalancing::LoadBalancer Properties: Subnets: Ref: Subnet HealthCheck: HealthyThreshold: '2' Interval: '10' Target: HTTP:80/health Timeout: '8' UnhealthyThreshold: '6' Listeners: - InstancePort: '80' InstanceProtocol: HTTP LoadBalancerPort: '8080' Protocol: HTTP - InstancePort: '80' InstanceProtocol: HTTP LoadBalancerPort: '443' Protocol: HTTPS SSLCertificateId: Ref: SSLArn SecurityGroups: - Ref: ELBSG

    以下是关于更新监听规则的:

    Listener: Type: AWS::ElasticLoadBalancingV2::Listener Properties: DefaultActions: - Type: forward TargetGroupArn: Ref: myTargetGroup LoadBalancerArn: Ref: myLoadBalancer Port: '8080' Protocol: HTTP

    我希望这就是您想要的。如果需要更多帮助,请更新。

    祝你好运。

    【讨论】:

    • 感谢您的回答!我想知道是否有办法以上述格式更新我现有的基于 yml 的规则?但是,我目前正在尝试将上述内容转换为 yml。
    • 会让你的生活更轻松 - 我转换并更新了上面的答案:)
    • 谢谢 :) 太棒了!
    • 没问题。请让我知道这是否有帮助。如果是这样,请不要忘记将其标记为已回答:) 谢谢
    • 谢谢,尽管此解决方案会创建一个新的负载均衡器,而不是更新现有的负载均衡器。我相信该解决方案将使用Type: AWS::ElasticLoadBalancingV2::ListenerRule
    猜你喜欢
    • 1970-01-01
    • 2020-03-14
    • 2018-02-15
    • 1970-01-01
    • 2020-03-22
    • 2022-07-27
    • 2013-10-25
    • 2018-01-24
    • 1970-01-01
    相关资源
    最近更新 更多