donald
donald

Reputation: 489

lambda timed out when trying to access mongo

I wrote a simple mongo test, trying to access mongo server in a vpc. for every run I get : "errorMessage": "*** Task timed out after 3.00 seconds" I have written more handlers in the lambda just to check it.

  1. There is no problem connecting to the vpc. other handler (same file) that connects to another server runs well.
  2. There is no problem with other modules. I have added another module (make-random-string) and it's running every time.
  3. I get no error messages. No exceptions from Mongo. it just times out every time.
  4. increasing both memory to 1024 and execution time to 15s didn't help, the results are the same.
  5. Mongo driver does not require any C++ builds unless you use kerberos, which I'm not.
  6. Test file mimicking the lambda, runs fine.
  7. The sample code is here: http://pastebin.com/R2e3jwwa where the db information is removed.

Thanks.

Upvotes: 5

Views: 5244

Answers (2)

Goran Miric
Goran Miric

Reputation: 31

I had the same issue. The solution was to move the database connection object outside the handler method and cache/reuse it.

Here I added more details about it: https://stackoverflow.com/a/67530789/10664035

Upvotes: 1

Alberto Centelles
Alberto Centelles

Reputation: 1253

As weird as it may sound, we finally solved the problem just by changing the callback(null, response) to context.done(null, response). This nonsense took us more time than we would have liked to spend here.

You can find more info about the issue here https://github.com/serverless/serverless/issues/1036

Upvotes: 4

Related Questions