'AWS ELB unhealthy 4xx
I am using express.js and graphql for backend server which uses port 4000. I am trying to connect my server with ELB but the status returns unhealthy with error code 400 or 404. These are my settings about ELB.
- Target group
- Target groups registered targets
- Target groups health checks
If I change the path to /graphql
it returns 400, and just /
returns 404. It is still working with no error when I call the API but it seems like I should fix it. Could anyone please tell me what can I do?
Solution 1:[1]
The standard way to handle this case is to define the path in your express application for example /health
or /ping
which should return HTTP status code 200
.
If /graphql
does not return HTTP status code 200
the LB will mark the target unhealthy.
you have two option
- Update Success codes to
400
, the LB will mark the target healhty - Define path like
/
or/health
and return status code200
.
In express for example
app.get('/health',function(req,res){
res.status(200).send("instance is healthy");
})
Or if you want to go without changing in the application the below will work.
Solution 2:[2]
Apollo supports a simple health check by default at this URL /.well-known/apollo/server-health (source), so you can add change the path in the target group from / to the URL
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | ngthanh |