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 →
- Point the health check at a real endpoint:
aws elbv2 modify-target-group --target-group-arn <tg-arn> --health-check-path /healthz - 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.