Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 294
donald Avatar asked Jul 20 '16 09:07

donald


People also ask

Why does my Lambda timeout?

There are three reasons why retry and timeout issues occur when invoking a Lambda function with an AWS SDK: A remote API is unreachable or takes too long to respond to an API call. The API call doesn't get a response within the socket timeout.

Can we use MongoDB with AWS Lambda?

Use the following best practices to properly manage connections between AWS Lambda and Atlas: Define the client to the MongoDB server outside the AWS Lambda handler function. Don't define a new MongoClient object each time you invoke your function.


1 Answers

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

like image 189
Alberto Centelles Avatar answered Sep 24 '22 09:09

Alberto Centelles