Reputation: 2730
I am using cloud formation template to build the infrastructure (ECS Fargate cluster). Template executed successfully and stack has been created successfully. However, task has failed with the following error:
Task failed ELB health checks in (target-group arn:aws:elasticloadbalancing:eu-central-1:890543041640:targetgroup/prc-service-devTargetGroup/97e3566c8b307abf)
I am not getting what and where to look for this to troubleshoot the issue. As it is Fargate cluster, I am not getting how to login to container and execute some health check queries to debug further.
Can someone please help me to guide further on this and help me? Due to this error, I am not even able to access my web app. As ALB won't route the traffic if it is unhealthy.
What I did
After some googling, I found this post: https://aws.amazon.com/premiumsupport/knowledge-center/troubleshoot-unhealthy-checks-ecs/
However, I guess, this is related to EC2 compatibility in Fargate. But in my case, EC2 is not there.
Upvotes: 79
Views: 130505
Reputation: 1
If your create with pipeline using cloudformation, my recomedation chaging 2 parameters in your template. Example :
[First step]
Type: AWS::ECS::Service
Properties:
HealthCheckGracePeriodSeconds: 60
[Second step]
TargetGroup:
Type: AWS::ElasticLoadBalancing::TargetGroup
Properties:
Port: !Ref ListenerContainerPort
Protocol: TCP
VpcId: !Ref VPCID
TargetType: ip
HealthCheckTimeoutSeconds: 40
HealthCheckIntervalSeconds: 100
When your deploy finish with sucess and the task stop the error.
Upvotes: 0
Reputation: 91
Some possible solutions for ECS
Upvotes: 1
Reputation: 91
I follwed the aws's provided blogs and my fix was ping path was incorrectly configured in LB w.r.t in apllication.
https://docs.aws.amazon.com/AmazonECS/latest/userguide/troubleshoot-service-load-balancers.html
https://aws.amazon.com/premiumsupport/knowledge-center/ecs-fargate-health-check-failures/
Upvotes: 0
Reputation: 960
In my case it was a security group rule which allowed connections only from a certain IP, and this was blocking healthchecks from LB. I added VPC's cidr as another rule to the security group and then it worked.
Upvotes: 0
Reputation: 1
I have also faced the same issue while using the AWS Fargate.
Here are some possible solutions to try:
Upvotes: 0
Reputation: 21
I had the same issue with deploying a java springboot app on ACS running as a fargate. There were 3 issues which I had to address to fix the problem, if this can help others in future.
The container was running on port 8080 (because of tomcat), so the ELB, target group and the two security groups (one with ELB and one with ECS) must allow 8080 in their inbounds rules. Also the task set up had to be revised to change the container to map at 8080.
The port on target group health check section (advance settings) had to be explicitly changed to 8080 instead of 80 as the default.
I had to create a dummy health check path in the application because pinging the root of the app at "/" was resulting in a 302 error code.
Hope this helps.
Upvotes: 2
Reputation: 513
My case was a React application running on FARGATE mode.
The first issue was that the Docker image was built over NodeJS "serving" it with:
CMD npm run start # react-scripts start
Besides that's not a good practice at all, it requires a lot of resources (4GB & 2vCPU were not enough), and because of that, the checks were failing. (this article mentions this as a probable cause)
To solve the previous issue, we modify the image as a multistage build with NodeJS for the building phase + NGINX for serving the content. Locally that was working great, but we haven't realized that the default port for NGINX is 80, and you can not use a different host and container port on FARGATE with awsvpc network mode.
To troubleshoot it, I launched an EC2 instance with the right Security Groups to connect with the FARGATE targets on the same port the Load Balancer was failing to perform a Health Check. I was able to execute curl's commands against other targets, but with this unhealthy target (constantly being recycled) I received an instant Connection refused response. It wasn't a timeout, which told me that the target was not able to manage that request because it was not listening to that port. Then I realized that my container was expecting traffic on port 80 and my application was configured to work on a 3xxx port.
The solution here was to modify the default configuration of NGINX to listen to the port we wanted, re-build the image and re-launch the service.
Upvotes: 2
Reputation: 171
Solution is partial correct in response 'iravinandan', but in last part of your nodejs router just simple add status(200)
and that's it. Or you can set your personal status clicking on advance tab, on end of the page.
app.get('/__health', (request, response) => response.status(200).end(""));
More info here: enter link description here
Regards
Upvotes: 0
Reputation: 737
In my case, ECS Fargate orchestration of the docker container functionality as a service and not a Web app or API. The service is that is not listening to any port (eg: Schedule corn/ActiveMQ message consumer ...etc).
In order words, it is a client and not a server node. So I made to listen to localhost for health check only...
All I added health check path in Target Group to -
And below code in index.ts -
import express from 'express';
const app = express();
const port = process.env.PORT || 8080;
//Health Check
app.get('/__health', (_, res) => res.send({ ok: 'yes' }));
app.listen(port, () => {
logger.info(`Health Check: Listening at http://localhost:${port}`);
});
Upvotes: 1
Reputation: 4154
Let me share my experience.
In my case everything was correct, except the host on which the server listens, it was localhost
which makes the server not reachable from the outside world and respectively the health check didn't work. It should be 0.0.0.0
or empty in some libraries.
Upvotes: 12
Reputation: 1712
Possibly helpful for someone.. our target group health check path was set to /
, which for our services pointed to Swagger and worked well. After updating to use Springfox instead of manually generating swagger.json, /
now performs a 302 redirect to /swagger-ui.html
, which caused the health check to fail. Since this was for a Spring Boot service we simply pointed the health check path in the target group to /health
instead (OOTB Spring status page).
Upvotes: 0
Reputation: 7424
There are quite a few of different possible reasons for this issue, not only the open ports:
Therefore AWS created an own website in order to address the possibilities of this error:
Edit: in my case the health check code of my application was different. The default is 200 but you can also add a range such as 200-499.
Upvotes: 20
Reputation: 752
As mentioned by tschumann above, check the security group around the ECS cluster. If using Terraform, allow ingress to all docker ephemeral ports with something like below:
resource "aws_security_group" "ecs_sg" {
name = "ecs_security_group"
vpc_id = "${data.aws_vpc.vpc.id}"
}
resource "aws_security_group_rule" "ingress_docker_ports" {
type = "ingress"
from_port = 32768
to_port = 61000
protocol = "-1"
cidr_blocks = ["${data.aws_vpc.vpc.cidr_block}"]
security_group_id = "${aws_security_group.ecs_sg.id}"
}
Upvotes: 1
Reputation: 3256
I got this error message because the security group between the ECS service and the load balancer target group was only allowing HTTP and HTTPS traffic.
Apparently the health check happens over some other port and or protocol as updating the security group to allow all traffic on all ports (as suggested at https://docs.aws.amazon.com/AmazonECS/latest/userguide/create-application-load-balancer.html) made the health check work.
Upvotes: 5
Reputation: 589
I had this exact same problem. I was able to get around the issue by:
Upvotes: 3
Reputation: 2730
This is resolved. It was the issue with the following points:
after making these changes, it worked properly
Upvotes: 44