LoadBalancer health check fails but instance is not terminating

0

Hello,

I have a load balancer which as you know keeps the health check for the web app/website.

I have deployed nothing in my instance means no app/site so when anyone visits the Loadbalancer URL they see a 502 Bad gateway error which is fine.

and also in the target group, it shows that an instance has failed the health check but the thing is that the auto-scaling group is not terminating the failed health check instance and replacing it.

Below is the Cloudformation code

AutoScailingGroup:
    Type: AWS::AutoScaling::AutoScalingGroup
    Properties:
      VPCZoneIdentifier:
       - Fn::ImportValue: !Sub ${EnvironmentName}-PR1
       - Fn::ImportValue: !Sub ${EnvironmentName}-PR2
      LaunchConfigurationName: !Ref AppLaunchConfiguration
      MinSize: 1
      MaxSize: 4
      TargetGroupARNs: 
        - Ref: WebAppTargetGroup

  AppLoadBalancer:
    Type: AWS::ElasticLoadBalancingV2::LoadBalancer
    Properties:
      SecurityGroups:
        - Ref: ApplicationLoadBalancerSecurityGroup
      Subnets:
       - Fn::ImportValue: !Sub ${EnvironmentName}-PU1
       - Fn::ImportValue: !Sub ${EnvironmentName}-PU2
      Tags:
       - Key: Name
         Value: !Ref EnvironmentName

  Listener:
    Type: AWS::ElasticLoadBalancingV2::Listener
    Properties:
      DefaultActions:
        - Type: forward
          TargetGroupArn: !Ref WebAppTargetGroup
      
      LoadBalancerArn: !Ref AppLoadBalancer
      Port: "80"
      Protocol: HTTP

  LoadBalancerListenerRule:
    Type: AWS::ElasticLoadBalancingV2::ListenerRule
    Properties:
      Actions:
      - Type: forward
        TargetGroupArn: !Ref WebAppTargetGroup
      Conditions:
      - Field: path-pattern
        Values: [/]
      ListenerArn: !Ref Listener
      Priority: 1

  WebAppTargetGroup:
    Type: AWS::ElasticLoadBalancingV2::TargetGroup
    Properties:
      HealthCheckIntervalSeconds: 10
      HealthCheckPath: /
      HealthCheckProtocol: HTTP
      HealthCheckTimeoutSeconds: 8
      HealthyThresholdCount: 2
      Port: 80
      Protocol: HTTP
      UnhealthyThresholdCount: 5
      VpcId:
        Fn::ImportValue:
            Fn::Sub: "${EnvironmentName}-VPCID"

  
  

  

1 Answer
1
Accepted Answer

Is this a new stack (aka, it wasn't working with healthy instances before)? If so, then the target group won't be in the InService state, meaning the ASG won't ever mark an instance unhealthy for failing ELB healthchecks for that target group. AutoScaling does this to prevent an infinite launch/terminate loop

https://docs.aws.amazon.com/autoscaling/ec2/APIReference/API_DescribeLoadBalancerTargetGroups.html

Once that ASG has seen a single instance has ever been healthy on that target group, it will move the target group from the Added state to the InService state and replacements will happen like normal.

I've send some documentation feedback to the AutoScaling team to get this information added to the ELB Healthcheck for AutoScaling docs instead of just existing in the API docs like it currently does.

AWS
answered 2 years ago
  • Wow. Never thought in this way regarding Target group States. Thanks man!

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions