dougmoscrop / serverless-http

Use your existing middleware framework (e.g. Express, Koa) in AWS Lambda 🎉
Other
1.73k stars 167 forks source link

Setting node.js keepAliveTimeout #203

Closed ozandogrultan closed 3 years ago

ozandogrultan commented 3 years ago

Hi, first of all thank you for this great library.

My question is related to the possibility of setting/updating nodejs' http.Server API settings while using serverless-http, mainly keepAliveTimeout (https://nodejs.org/api/all.html#http_server_keepalivetimeout)

The reason for me trying to set this is summed up in this short article. We are currently using serverless-http with AWS ELB+Lambda+Express and it seems like serverless-http doesn't expose any configuration to set nodejs' Server API settings. Is there any way to do this?

Thanks a lot in advance.

dougmoscrop commented 3 years ago

Hey, I am struggling to see how this would help you, as there isn't actually a server listening, this library presents a mock/fake version of node.js internal request/response classes, but your ELB isn't actually ever talking to Express on anything like a TCP port.

Your ELB is talking to the Lambda invoke infrastructure, which is entire AWS owned; when your ELB forwards a request, the Lambda service is putting that request in to a queue of sorts, and then your Lambda containers (could be one, could be thousands, depending on how much traffic you're seeing) are all running what basically amounts to a while true loop and polling that queue for new events, they process the event, and then the send the response back again - this is all done via HTTP, but it's a completely different.. I don't know the right word, Stream? Pipeline? Like it has nothing to do with your HTTP code.

When you actually look at the whole picture, it's a very weird HTTP-inside-of-HTTP-via-HTTP type system which is a Frankenstein but that's all before a line of your (or my) code is even run.

Does any of that make sense? Like there is no socket, at all, that is involved in any of your or my code, it's all fake, and the only actual listeners/sockets open are entirely owned and controlled by AWS (and there's like, two pairs of them)

ozandogrultan commented 3 years ago

Hi @dougmoscrop, thanks for the fast response and the clarification. There was apparently some confusion from my side but it's all clear now. We'll try to debug the 502 errors by checking ELB logs as suggested by AWS support.