AWS ELBv2 with All Unhealthy Targets

Description:

Elastic Load Balancer v2 (Application or Network Load Balancer) distributes incoming traffic to its registered targets (e.g., EC2 instances). If all the targets are unhealthy, it means that the Load Balancer cannot forward traffic, leading to service outages. Monitoring target health is crucial to ensure high availability and reliability of the services.


Remediation:

1. Verify Target Health:

AWS Management Console:
  • Navigate to the EC2 Dashboard.
  • Under Load Balancing in the left-hand pane, select Target Groups.
  • Choose the target group associated with the ELBv2.
  • Check the Targets tab. If all targets are listed as unhealthy, troubleshoot why they are failing health checks.
AWS CLI:
# Describe target health for a specific target group
aws elbv2 describe-target-health --target-group-arn <Your-Target-Group-ARN>

2. Troubleshoot Unhealthy Targets:

  • Check the health check configurations for the target group. Ensure that the health check endpoint in each target is responsive.
  • Examine instance status, network configurations, application logs, or other relevant metrics.
  • If the instances are stopped or terminated, replace or restart them.
Terraform:

You can ensure instances are created and attached to the target group.

resource "aws_lb_target_group" "example" {
  name     = "example"
  port     = 80
  protocol = "HTTP"
  vpc_id   = "<Your-VPC-ID>"
}

resource "aws_instance" "example" {
  ami           = "<Your-AMI-ID>"
  instance_type = "t2.micro"
  
  # ... other configurations ...

  tags = {
    Name = "example-instance"
  }
}

resource "aws_lb_target_group_attachment" "example" {
  target_group_arn = aws_lb_target_group.example.arn
  target_id        = aws_instance.example.id
  port             = 80
}

3. Adjust Health Check Configuration:

  • Modify the health check configuration to ensure it correctly checks the application or service. Adjust the threshold, interval, or health check endpoint if necessary.

It's critical to monitor the health of the targets attached to your Load Balancer to maintain high service availability. Use CloudWatch Alarms to notify if all targets become unhealthy. Consider using Auto Scaling groups to ensure that there's always a healthy number of instances serving the load balancer.