Getting error while deploying stack through CF- "the target must have at least one listener that matches the target group port"

0

Hello Team,

I am facing below error while creating the stack through cloudforamtion. I have already verified the CF template and not able to find root cause of this error.

"If the target type is AB, the target must have at least one listener that matches the target group port for any specific port override"

Request you to please assist to fix this error. Below is my CF template:- AWSTemplateFormatVersion: "2010-09-09" Description: "Create ALB, ALB security group, target groups, listeners and listener rules" Parameters: VPC: Type: String Description: The vpc to launch the service Default: vpc-53b04a34

PrivateSubnet1:
    Type: String
    Description: The subnet where to launch the service
    Default: subnet-814e77f7

PrivateSubnet2:
    Type: String
    Description: The subnet where to launch the service
    Default: subnet-759a7d12

Resources: ALBSecurityGroup1: Type: "AWS::EC2::SecurityGroup" Properties: GroupDescription: "security group for ALB" GroupName: "Gatling-ALB-SG-1" Tags: - Key: "Project" Value: "Gatling-ALB" - Key: "createdBy" Value: "Userhub" - Key: "Environment" Value: "stage" - Key: "Name" Value: "Gatling-ALB-SG" VpcId: !Ref VPC SecurityGroupIngress: - CidrIp: "0.0.0.0/0" FromPort: 80 IpProtocol: "tcp" ToPort: 80 - CidrIp: "0.0.0.0/0" FromPort: 80 IpProtocol: "tcp" ToPort: 80

ApplicationLoadBalancer:
    Type: "AWS::ElasticLoadBalancingV2::LoadBalancer"
    Properties:
        Name: "gatling-lb"
        Scheme: "internal"
        Type: "application"
        Subnets: 
          - !Ref PrivateSubnet1
          - !Ref PrivateSubnet2
        SecurityGroups: 
          - !Ref ALBSecurityGroup1
        IpAddressType: "ipv4"
        LoadBalancerAttributes: 
          - 
            Key: "access_logs.s3.enabled"
            Value: "false"
          - 
            Key: "idle_timeout.timeout_seconds"
            Value: "60"
          - 
            Key: "deletion_protection.enabled"
            Value: "false"
          - 
            Key: "routing.http2.enabled"
            Value: "true"
          - 
            Key: "routing.http.drop_invalid_header_fields.enabled"
            Value: "false"
Test1TargetGroup:
    Type: "AWS::ElasticLoadBalancingV2::TargetGroup"
    Properties:
        HealthCheckIntervalSeconds: 30
        HealthCheckPath: "/"
        Port: 80
        Protocol: "TCP"
        HealthCheckPort: "traffic-port"
        HealthCheckProtocol: "HTTP"
        HealthCheckTimeoutSeconds: 5
        UnhealthyThresholdCount: 2
        TargetType: "alb"
        Matcher: 
            HttpCode: "200"
        HealthyThresholdCount: 5
        VpcId: !Ref VPC
        Name: "target-group-gatling"
        HealthCheckEnabled: true
        Targets:
          - Id: !Ref ApplicationLoadBalancer
            Port: 80			
HTTPListener:
    Type: "AWS::ElasticLoadBalancingV2::Listener"
    Properties:
        LoadBalancerArn: !Ref ApplicationLoadBalancer
        Port: 80
        Protocol: "HTTP"
        DefaultActions: 
          - 
            Type: "forward"
            ForwardConfig:
              TargetGroups:
                - TargetGroupArn: !Ref Test1TargetGroup


NetworkLoadBalancer:
  Type: AWS::ElasticLoadBalancingV2::LoadBalancer
  Properties:
    Name: "gatling-network-lb"
    Scheme: internal
    Subnets:
      - !Ref PrivateSubnet1
    Type: network
NetworkLoadBalancerListener:
  Type: AWS::ElasticLoadBalancingV2::Listener
  Properties:
    DefaultActions:
      - Type: forward
        TargetGroupArn: !Ref Test1TargetGroup
    LoadBalancerArn: !Ref NetworkLoadBalancer
    Port: 80
    Protocol: TCP

Outputs:
ALB: Description: The created loadbalancer Value: !Ref ApplicationLoadBalancer

TargetGroup1:
    Description: The created TargetGroup 1
    Value: !Ref Test1TargetGroup


LoadBalancerSecurityGroup:
    Description: the securty group for the ALB
    Value: !Ref ALBSecurityGroup1
질문됨 일 년 전749회 조회
1개 답변
0

There seems to be a problem with the ALB target group "Test1TargetGroup".
ALB target groups cannot specify alb in the target type.
Also, I think we need to create separate target groups for ALB and NLB since the same target group is used in NLB.
Change the target type of the ALB target group to "instance" or "ip" depending on your environment.

ApplicationLoadBalancer:
    Type: "AWS::ElasticLoadBalancingV2::LoadBalancer"
    Properties:
        Name: "gatling-lb"
        Scheme: "internal"
        Type: "application"
        Subnets: 
          - !Ref PrivateSubnet1
          - !Ref PrivateSubnet2
        SecurityGroups: 
          - !Ref ALBSecurityGroup1
        IpAddressType: "ipv4"
        LoadBalancerAttributes: 
          - 
            Key: "access_logs.s3.enabled"
            Value: "false"
          - 
            Key: "idle_timeout.timeout_seconds"
            Value: "60"
          - 
            Key: "deletion_protection.enabled"
            Value: "false"
          - 
            Key: "routing.http2.enabled"
            Value: "true"
          - 
            Key: "routing.http.drop_invalid_header_fields.enabled"
            Value: "false"

Test1TargetGroup:
    Type: "AWS::ElasticLoadBalancingV2::TargetGroup"
    Properties:
        HealthCheckIntervalSeconds: 30
        HealthCheckPath: "/"
        Port: 80
        Protocol: "HTTP"
        HealthCheckPort: "traffic-port"
        HealthCheckProtocol: "HTTP"
        HealthCheckTimeoutSeconds: 5
        UnhealthyThresholdCount: 2
        TargetType: "instance"
        Matcher: 
            HttpCode: "200"
        HealthyThresholdCount: 5
        VpcId: !Ref VPC
        Name: "target-group-gatling"
        HealthCheckEnabled: true
        Targets:
          - Id: !Ref Ec2
            Port: 80

HTTPListener:
    Type: "AWS::ElasticLoadBalancingV2::Listener"
    Properties:
        LoadBalancerArn: !Ref ApplicationLoadBalancer
        Port: 80
        Protocol: "HTTP"
        DefaultActions: 
          - 
            Type: "forward"
            ForwardConfig:
              TargetGroups:
                - TargetGroupArn: !Ref Test1TargetGroup


NetworkLoadBalancer:
  Type: AWS::ElasticLoadBalancingV2::LoadBalancer
  Properties:
    Name: "gatling-network-lb"
    Scheme: internal
    Subnets:
      - !Ref PrivateSubnet1
    Type: network

NLBTargetGroup:
  Type: AWS::ElasticLoadBalancingV2::TargetGroup
  Properties:
    HealthCheckEnabled: true
    HealthCheckIntervalSeconds: 30
    HealthCheckPath: "/"
    HealthCheckPort: traffic-port
    HealthCheckProtocol: HTTP
    HealthyThresholdCount: 5
    IpAddressType: ipv4
    Name: "nlb-tg"
    Port: 80
    Protocol: TCP
    Targets:
      - Id: !Ref ApplicationLoadBalancer
        Port: 80
    TargetType: alb
    UnhealthyThresholdCount: 2
    VpcId: !Ref VPC

NetworkLoadBalancerListener:
  Type: AWS::ElasticLoadBalancingV2::Listener
  Properties:
    DefaultActions:
      - Type: forward
        TargetGroupArn: !Ref Test1TargetGroup
    LoadBalancerArn: !Ref NetworkLoadBalancer
    Port: 80
    Protocol: TCP
profile picture
전문가
답변함 일 년 전
  • Thanks for your reply. I have tried with different target groups for ALB and NLB as you suggested but still facing the same error while creation of NLB target group.

  • Sorry, there was an error in the CloudFormation template I presented. Change "TargetGroupArn" in the NLB listener from "!Ref Test1TargetGroup" to "!Ref NLBTargetGroup".

    NetworkLoadBalancerListener:
      Type: AWS::ElasticLoadBalancingV2::Listener
      Properties:
        DefaultActions:
          - Type: forward
            TargetGroupArn: !Ref NLBTargetGroup
        LoadBalancerArn: !Ref NetworkLoadBalancer
        Port: 80
        Protocol: TCP
    

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠