# Function invocation timeout error after connecting to a MongoDB cluster

**URL:** <https://forum.serverless.com/t/function-invocation-timeout-error-after-connecting-to-a-mongodb-cluster/11349>\
**Category:** Serverless Framework\
**Created:** [May 4, 2020, 10:28pm UTC](https://forum.serverless.com/t/function-invocation-timeout-error-after-connecting-to-a-mongodb-cluster/11349 "2020-05-04T22:28:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![SUDOH](https://avatars.discourse-cdn.com/v4/letter/s/9de053/32.png) [@SUDOH](https://forum.serverless.com/u/SUDOH)\
**Post date:** [May 4, 2020, 10:28pm UTC](https://forum.serverless.com/t/function-invocation-timeout-error-after-connecting-to-a-mongodb-cluster/11349/1 "2020-05-04T22:28:03Z")

</div>

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 --------------------------------------------
     Docs: docs.serverless.com
     Bugs: github.com/serverless/serverless/issues
     Issues: forum.serverless.com
 
  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.

---

<div class="post-metadata">

**Author:** ![keephopealive](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/keephopealive/32/4207_2.png) [@keephopealive](https://forum.serverless.com/u/keephopealive)\
**Post date:** [May 5, 2020, 1:58am UTC](https://forum.serverless.com/t/function-invocation-timeout-error-after-connecting-to-a-mongodb-cluster/11349/2 "2020-05-05T01:58:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![SUDOH](https://avatars.discourse-cdn.com/v4/letter/s/9de053/32.png) [@SUDOH](https://forum.serverless.com/u/SUDOH)\
**Post date:** [May 5, 2020, 6:18pm UTC](https://forum.serverless.com/t/function-invocation-timeout-error-after-connecting-to-a-mongodb-cluster/11349/3 "2020-05-05T18:18:22Z")

</div>

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

 ![1](https://canada1.discourse-cdn.com/flex036/uploads/serverless/original/2X/0/01d383d86a111620e270abbd7b3c03753726b7e4.png)

---

<div class="post-metadata">

**Author:** ![keephopealive](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/keephopealive/32/4207_2.png) [@keephopealive](https://forum.serverless.com/u/keephopealive)\
**Post date:** [May 6, 2020, 2:35am UTC](https://forum.serverless.com/t/function-invocation-timeout-error-after-connecting-to-a-mongodb-cluster/11349/4 "2020-05-06T02:35:06Z")

</div>

> [@SUDOH](#):
>
> For debugging logs, run again after setting the “SLS\_DEBUG=\*” environment variable.

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.

---

<div class="post-metadata">

**Author:** ![ellery](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/ellery/32/5129_2.png) [@ellery](https://forum.serverless.com/u/ellery)\
**Post date:** [January 24, 2021, 4:13pm UTC](https://forum.serverless.com/t/function-invocation-timeout-error-after-connecting-to-a-mongodb-cluster/11349/5 "2021-01-24T16:13:40Z")

</div>

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
