5

我有一些应用程序在 aws 中作为微服务运行。其中一些在端口 80 上运行,其中一些在端口 3000 上运行。我希望我的 ALB 监听两个端口上的流量。然后我必须ListenRules将流量引导到微服务。我想实现以下目标,

Resources:
  LoadBalancer:
    Type: AWS::ElasticLoadBalancingV2::LoadBalancer
    Properties:
      Name: !Ref EnvironmentName
      Subnets: !Ref Subnets
      SecurityGroups:
        - !Ref SecurityGroup
      Tags:
        - Key: Name
          Value: !Ref EnvironmentName

  LoadBalancerListener:
    Type: AWS::ElasticLoadBalancingV2::Listener
    Properties:
      LoadBalancerArn: !Ref LoadBalancer
      Port: [80,3000] # something like this
      Protocol: HTTP
      DefaultActions:
        - Type: forward
          TargetGroupArn: !Ref DefaultTargetGroup
4

1 回答 1

7

应该对每个要打开的端口重复侦听器。例如:

Resources:
LoadBalancer:
  Type: AWS::ElasticLoadBalancingV2::LoadBalancer
  Properties:
    Name: !Ref EnvironmentName
    Subnets: !Ref Subnets
    SecurityGroups:
      - !Ref SecurityGroup
    Tags:
      - Key: Name
        Value: !Ref EnvironmentName

LoadBalancerListenerA:
  Type: AWS::ElasticLoadBalancingV2::Listener
  Properties:
    LoadBalancerArn: !Ref LoadBalancer
    Port: 80
    Protocol: HTTP
    DefaultActions:
      - Type: forward
        TargetGroupArn: !Ref TargetGroupForPort80

LoadBalancerListenerB:
  Type: AWS::ElasticLoadBalancingV2::Listener
  Properties:
    LoadBalancerArn: !Ref LoadBalancer
    Port: 3000
    Protocol: HTTP
    DefaultActions:
      - Type: forward
        TargetGroupArn: !Ref TargetGroupForPort3000

这也允许为每个端口设置不同的协议(例如 HTTPS)或目标组的灵活性。

于 2019-01-01T22:18:49.140 回答