问题
My app is running on port 3000 and web context is /app, so "http://host:3000/app/index.html" successfully returns index.html page running the app locally.
Load balancer(public) listens on port 80 and forwards traffic to targets on port 3000.
AWS Fargate - task definition has host and container port mapped to port 3000. - tasks are shown as RUNNING and status HEALTHY but eventually stops because ELB health checks fails. And i am able to see my app start up logs in cloud watch (tasks -> logs). - Security group of cluster service is receiving inbound traffic on custom tcp port 3000.
I have tried by updating TargetGroup health checks to use paths as "/", "/app" and "/app/index.html" but this does not work either.
回答1:
First verified that:
- your application starts within errors in the container.
- your security configuration allows traffic between ECS and the ELB.
- your health checks are pointing to the right path.
It's time to take a look at the ELB logs, you can enable them following this tutorial.
With the ECS Service logs, ECS task logs and ELB logs you can determine how long takes for your application to be up & running, once you know that, configure the ECS Service grace period to that value.
Once your grace period is big enough to allow the previously explained to happen, your application will pass the health checks.
For example in our case a Spring Boot application that takes about 20 seconds to start in an EC2 instance, it can take more than 3 minutes to be reachable on an ECS Fargate service, therefore we set our grace period to 240 seconds and that solved the issue.
回答2:
You need to configure the TargetGroup health checks to use the 3000 port because in your application is listening in 3000 port and the ALB send the request to the task that is running in that port, you can do it going to TargetGroup health checks tab and in the option Port select override. If you created an ECS service, please verify the Health check grace period, in some cases, the task can take a lot of time to start correctly.
来源:https://stackoverflow.com/questions/61175084/aws-fargate-application-load-balancerelb-shows-unhealthy-targets-with-error