Function invocation timeout error after connecting to a MongoDB cluster

I have some issues with serverless & MongoDB cluster connection. I am able to successfully run serverless locally on my computer but whenever I connect to my MongoDB cluster, I get the following time out message after invoking a function:

    "errorMessage": "2020-05-04T21:45:54.155Z 38b7358e-2b16-4c93-9e43-76991ebd6fb1 Task timed out after 6.01 seconds"
  Error --------------------------------------------------
  Error: Invoked function failed
      at AwsInvoke.log (/usr/local/lib/node_modules/serverless/lib/plugins/aws/invoke/index.js:105:31)
      at AwsInvoke.tryCatcher (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/util.js:16:23)
      at Promise._settlePromiseFromHandler (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:547:31)
      at Promise._settlePromise (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:604:18)
      at Promise._settlePromise0 (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:649:10)
      at Promise._settlePromises (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:729:18)
      at _drainQueueStep (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:93:12)
      at _drainQueue (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:86:9)
      at Async._drainQueues (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:102:5)
      at Immediate.Async.drainQueues (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:15:14)
      at runCallback (timers.js:794:20)
      at tryOnImmediate (timers.js:752:5)
      at processImmediate [as _immediateCallback] (timers.js:729:5)
     For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.
  Get Support --------------------------------------------
  Your Environment Information ---------------------------
     Operating System:          linux
     Node Version:              8.10.0
     Framework Version:         1.69.0
     Plugin Version:            3.6.9
     SDK Version:               2.3.0
     Components Version:        2.30.5


I’m just wondering if anyone can point me to what I must have missed.

I believe task timeout can also occur when you do not have the proper configuration to connect to your db cluster. Have you re-re-re-reconfirmed the ip? Are you going through a ec tunnel to get to your db? Is this running in AWS? I know the default config on aws is that you cant connect directly to the DB, you have to create an EC2 to use as a tunnel, and ensure the ec2 has a security group allowing external ips, and must also be in AWS’s internal subnet - the same as your DB is. I’m assuming both are in AWS.

Sorry I’m making a lot of assumptions here but maybe you can at least check that as a non issue if you’re already familiar and have checked these settings, or share with us roughly the configuration you have going on here.

1 Like

Thanks @keephopealive for your response. I don’t have to do any configuration as MongoDB takes care of the configurations and provided a URI connection string which the serverless lambdas need to connect to the database.
Locally everything works fine but when I tried connecting to the cluster, it time out.

See attached

Are these logs the most you can get out of debugging, including using the above environment variable?

Unless its the incorrect IP connecting to the DB, or the authorization is not failing to connect to that IP, its hard to tell without more data, though I wonder if anyone else has any other thoughts.

Did you ever figure out why this was happening? I’m running into a similar issue now. Code works well locally but getting this odd issue connecting to Atlas