Reputation: 21
I'm new to Node.js, my question could be stupid to someone, please forgive me for this.
In the past, I have Apache installed on an EC2 instance. I created ping.html inside this directory /var/www/html/ping.html.
And the Health Check would be: Ping Port:80, Ping Path:/ping.html.
I don't know how to do the same thing like above for Node.js. Where should I create this ping.html file, because Node.js has no such directory /var/www/html/? Or what should I do to pass the ELB Health check for Node.js?
I read a lot of instructions, but it seems it is "too much" for me to get it.
Upvotes: 1
Views: 3425
Reputation: 141678
It depends on what you want to check and what you are using with node.js. If you just wanted the check to make sure that the node.js server is running, you could simply add this to the HTTP server:
var server = http.createServer(function(request, response) {
if (request.url === '/ping.html' && request.method ==='GET') {
//AWS ELB pings this URL to make sure the instance is running
//smoothly
response.writeHead(200, {
'Content-Type': 'text/plain',
'Content-Length': 2
});
response.write('OK');
response.end();
}
//Do the rest of your web server here
});
server.listen(8080 /* Whatever port */);
If you are using something with node that servers content like express.js then you could just make the ELB check the content of a page that express.js serves.
Upvotes: 2