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"
Wow. Never thought in this way regarding Target group States. Thanks man!