Getting timeouts on second request using express-session and serverless-http

Hi there,

We are moving our existing ExpressJS REST API over to Serverless using serverless-http/AWS/Lambda and have a problem with express-session. We’ve done what we think is correct:

  • Of course using data store, not MemoryStore.
  • First we tried to keep existing PostgreSQL data store for session.
  • When that did not work we assumed it was because of database connection/pool.
  • Now we changed to using DynamoDB as data store for express-session.
  • But same problem persists.

Details about the problem:

  • Hitting the API endpoint first time is fine, response is coming correctly back.
  • But the second time and onwards 502 Bad Gateway “internal server error” returnended.
  • Waiting long enough we get a 200 again, problem when Lambda function is cold.

If I comment out the express-session code it works as it should. Has anyone succeded in using express-session with Serverless/Lambda?

Thanks,
Marius