Interview Prep/AWS/EC2, Auto Scaling and Load Balancing

Target health shows `Target.ResponseCodeMismatch: Health checks failed with these codes: [404]`.

IntermediateTroubleshootingEC2, Auto Scaling and Load Balancing
Answer

Likely causes → The health check path does not exist on the app, or it redirects (301/302) to HTTPS or a login page. By default, the matcher only accepts 200.

Diagnose →

aws elbv2 describe-target-groups --target-group-arns <tg-arn> \
  --query 'TargetGroups[].[HealthCheckPath,HealthCheckPort,Matcher.HttpCode]'
# from an instance in the same subnet:
curl -i http://10.0.1.25:8080/health

Fix →

  1. Point the health check at a real endpoint: aws elbv2 modify-target-group --target-group-arn <tg-arn> --health-check-path /healthz
  2. Or widen the matcher if the endpoint legitimately returns another code: --matcher HttpCode=200-299

Prevent → Every service exposes an unauthenticated /healthz that does not redirect, and IaC defines it next to the target group.

aws All AWS questions Roadmap: AWS core services

More on EC2, Auto Scaling and Load Balancing