Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AWS::ElasticLoadBalancingV2::ListenerRule is ForwardConfig supported for application load balancer and not for network load balancer? #385

Closed
morinrod-cardioscan opened this issue Feb 18, 2020 · 1 comment
Labels
networking & content deliv VPC, CloudFront, Route 53, API Gateway, Direct Connect, AWS App Mesh, etc.

Comments

@morinrod-cardioscan
Copy link

AWS::ElasticLoadBalancingV2::ListenerRule - Is ForwardConfig supported for application load balancer and not for network load balancer?

Expected behavior: When trying to create a listener rule for weighted target groups with a network load balancer(ECS service with blue green deployment using CodeDeploy), it gives an error:

You cannot specify multiple target groups in a single action with a load balancer of type 'network' (Service: AmazonElasticLoadBalancingV2; Status Code: 400; Error Code: ValidationError; Request ID: 93c2a425-6f84-454e-b113-0c380f1e6479)

It is possible to configure that in the console, when creating ECS service with blue/green deployments using AWS CodeDeploy, with network load balancer.

Test case: Network load balancer was configured.
See the CloudFormation template below.
Links to doc:
Support for ForwardConfig in a listener rule with application load balancer was added recently:
https://aws.amazon.com/blogs/aws/new-application-load-balancer-simplifies-deployment-with-weighted-target-groups/
and:
aws-cloudformation/cfn-lint#1251
Category: Compute

Resources:
  taskdefinition:
    Type: AWS::ECS::TaskDefinition
    Properties:
      ContainerDefinitions:
        - Name: !Ref ContainerName
          Image: !Ref ECRImage
          Cpu: !Ref ContainerCPU
          PortMappings:
            - ContainerPort: !Ref AppContainerPort
              HostPort: !Ref AppHostPort
          Memory: !Ref ContainerMemory
          Essential: true
      NetworkMode: awsvpc
      Cpu: !Ref TaskCpu
      ExecutionRoleArn: !Ref ecsTaskExecutionRoleArn
      Family: !Ref TaskDefinitionFamily
      Memory: !Ref TaskMemoryInGB
      RequiresCompatibilities: 
        - FARGATE
        - EC2
  TargetGroup1:
    Type: AWS::ElasticLoadBalancingV2::TargetGroup
    Properties:
      Name: !Join [ "", [ 'tg-', !Ref ClusterName, '-', !Ref ServiceName,'1' ] ]
      Port: !Ref ListenerPort
      Protocol: TCP
      HealthCheckProtocol: TCP
      TargetType: ip
      Targets:
        - Id: ''
      VpcId: !Ref VpcId
  TargetGroup2:
    Type: AWS::ElasticLoadBalancingV2::TargetGroup
    Properties:
      Name: !Join [ "", [ 'tg-', !Ref ClusterName, '-', !Ref ServiceName,'2' ] ]
      Port: !Ref ListenerPort
      Protocol: TCP
      HealthCheckProtocol: TCP
      TargetType: ip
      Targets:
        - Id: ''
      VpcId: !Ref VpcId
  Listener:
    Type: AWS::ElasticLoadBalancingV2::Listener
    Properties:
      DefaultActions: 
        - Type: "forward"
          TargetGroupArn: !Ref TargetGroup1
      LoadBalancerArn: !Ref LoadBalancerArn
      Port: !Ref ListenerPort
      Protocol: TCP
  ListenerRule1:
    Type: 'AWS::ElasticLoadBalancingV2::ListenerRule'
    Properties:
      Actions:
        - Type: forward
          ForwardConfig:
            TargetGroups:
              - TargetGroupArn: !Ref TargetGroup1
                Weight: 1
              - TargetGroupArn: !Ref TargetGroup2
                Weight: 0      
      ListenerArn: !Ref Listener
      Priority: 1
      Conditions: 
        - Field: path-pattern
          Values:
            - foo
  service:
    Type: AWS::ECS::Service
    DependsOn:
    - Listener
    - ListenerRule1
    Properties:
      Cluster: !Ref ClusterName
      DeploymentConfiguration:
        MaximumPercent: 200
        MinimumHealthyPercent: 100
      DeploymentController: 
        Type: CODE_DEPLOY
      DesiredCount: !Ref TasksNumber
      HealthCheckGracePeriodSeconds: !Ref HealthCheckGracePeriodSeconds
      LaunchType: FARGATE
      LoadBalancers:
        - ContainerName: !Ref ContainerName
          ContainerPort: !Ref AppContainerPort
          TargetGroupArn: !Ref TargetGroup1
        - ContainerName: !Ref ContainerName
          ContainerPort: !Ref AppContainerPort
          TargetGroupArn: !Ref TargetGroup2
      PlacementStrategies:
        - Type: binpack
          Field: memory
        - Type: spread
          Field: host
      TaskDefinition: !Ref taskdefinition
      ServiceName: !Ref ServiceName
      NetworkConfiguration: 
         AwsvpcConfiguration: 
          AssignPublicIp: ENABLED,
          SecurityGroups: 
            - !Ref SecurityGroups
          Subnets: 
            - !Ref Subnet1
            - !Ref Subnet2  
@luiseduardocolon luiseduardocolon added the networking & content deliv VPC, CloudFront, Route 53, API Gateway, Direct Connect, AWS App Mesh, etc. label Feb 27, 2020
@dogipd
Copy link

dogipd commented Sep 2, 2021

From the ELB public documentation for the ForwardConfig action, You can only specify one target group with the ForwardConfig listener-rule action with Network Load Balancers so weighed target groups is not supported.

https://docs.aws.amazon.com/elasticloadbalancing/latest/APIReference/API_ForwardActionConfig.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
networking & content deliv VPC, CloudFront, Route 53, API Gateway, Direct Connect, AWS App Mesh, etc.
Projects
None yet
Development

No branches or pull requests

4 participants