Closed LoneRifle closed 6 years ago
Further comments - serverPromise
is removed from the context before the event is proxied to the server, in order to prevent it from being serialized to string (and hence triggering an error relating to JSON circular structures)
Closing on realising that I have to pass the original context, not a copy. Further work will be done so that passing the original does not result in the problems stated earlier
The current template implementation of serverless proxy appears to derive from the example from aws-serverless-express. That example (and hence this template) will create one
http.Server
per lambda invocation. This introduces significant delay, and for spiky traffic, would result inhttp.Server
objects being thrown away when the excess lambda instances are removed.This change attempts to improve things by storing an
http.Server
wrapped in a Promise in the execution context provided by AWS Lambda. The first lambda invocation will create theserverPromise
and save it in the context. Subsequent invocations can then use this.Given node assumes there is only a single thread of execution, it is obvious that there would be a race condition between two lambda invocations in creating and saving the
serverPromise
. This should only be a minor problem since the server itself is stateless and can be easily replaced without consequence.