Can NLB support mulitple target groups in one listener?

0

When building a network load balancer with the cloud formation, I got the following error:

  • you cannot specify multiple target groups in a single action with a load balancer of type 'network' I am adding two target groups in a single default action for a network listener, the part of cloud formation is at the bottom of the page.

If I create a NLB with 2 AZs, how can I add two target groups for 2 AZs into one listener of the NLB? I thought this would make the NLB fault-tolerant, but elastic load balancing doesn't allow this.

I have to work around this by adding targets in 2 AZs into one target group associating with the listener, but this will make load balancing cross the AZs which might cause higher latency and data transfer fees for NLB.

 NLB:
    Type: AWS::ElasticLoadBalancingV2::LoadBalancer
    Properties:
      Name: !Sub "${NetworkStackName}-nlb"
      Scheme: "internet-facing"
      SecurityGroups: 
        - Fn::ImportValue: 
            'Fn::Sub': '${NetworkStackName}-PubSecurityGroupID'
      Subnets:
        - Fn::ImportValue: 
            'Fn::Sub': '${NetworkStackName}-PublicSubnetID-1'
        - Fn::ImportValue: 
            'Fn::Sub': '${NetworkStackName}-PublicSubnetID-2'    
      Tags:
      - Key: Name
        Value: !Sub "${NetworkStackName}-nlb"
      Type: "network"

  NLBListener1:
    Type: AWS::ElasticLoadBalancingV2::Listener
    Properties:
      DefaultActions: 
        - Type: forward
          ForwardConfig:
            TargetGroups: 
              - TargetGroupArn:
                  Fn::ImportValue: 
                    'Fn::Sub': '${NetworkStackName}-nlb-target-group-1'      
        - Type: forward
          ForwardConfig:
            TargetGroups: 
              - TargetGroupArn:
                  Fn::ImportValue: 
                    'Fn::Sub': '${NetworkStackName}-nlb-target-group-2'                                   
      LoadBalancerArn: !Ref NLB
      Port: 80
      Protocol: TCP
gefragt vor 4 Monaten251 Aufrufe
1 Antwort
1
Akzeptierte Antwort

To achieve what your looking for is to add 2 targets in one target group on your listener and then disable cross zone load balancing.

When cross-zone load balancing is off, each load balancer node distributes traffic across only the registered targets in its Availability Zone.

profile picture
EXPERTE
beantwortet vor 4 Monaten
profile picture
EXPERTE
überprüft vor 2 Monaten
  • I might misunderstand the Target Group definition. I thought it was AZ-related but not. It seems a Target Group is just a virtual container including the targets from different AZs. Regarding the NLB, cross-zone load balancing is off by default, so the traffic is always routed to the targets in the same AZ.

    Is this a correct understanding?

  • You are correct with your understanding. A target group isn’t specific per AZ and multi AZ is disabled by default on a network load balancer.

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen