2

I am working on AWS lambda functions (NodeJS) that connects to a MongoDB server running on EC2 Instance. Lambda function is place in a VPC-1 and MongoDB server (EC2 Instance) is in VPC-2.

We have setup VPC peering between VPC-1 and VPC-2

The lambda function is intermittently throwing timeout error. It works 50% of the time and 50% of the time, it's throwing timeout error.

Note: The MongoDB is running on an EC2 Instance is specially setup for the development of this project. It does not get any additional traffic.

Also, another component of this project developed in NodeJS again running from another EC2 instance can communicate with the MongoDB server without any timeout issues.

Could someone help me in understanding the possible cause of the timeout issues?

Thanks in advance.

Faisal
  • 31
  • 2

2 Answers2

1

Hope below article might solve your problem:

To fix: Increase the timeout setting/memory on the configuration page of your Lambda function

For nodejs async related issues, please refer below link:

AWS Lambda: Task timed out

  • Thanks for you reply. The timeout and memory has already been increased to 60 sec which is enough for a nodejs app to make a connection to mongo. When everything works fine then I get a response in milliseconds but in the timeout scenario, even 60 is less to do the processing. – Faisal May 16 '20 at 08:22
  • Check the mentioned article looks like required some changes in mongodb server configuration How to fix MongoDB connection timeout? - Bobcares – Shaunak Sen May 16 '20 at 11:00
  • https://mongodb.github.io/node-mongodb-native/2.0/reference/connecting/connection-settings/ – Shaunak Sen May 16 '20 at 11:03
0

Lambda timeouts can best be described as

The amount of time that Lambda allows a function to run before stopping it. The default is 3 seconds. The maximum allowed value is 900 seconds.

Within the console you can increase this timeout to a greater number.

When you click on the Lambda function there will be a monitoring tab. From here you should be able to see execution time of Lambda functions. You might find that its always close to the bar.

I'd recommend increasing the timeout a bit higher than you anticipate it needs then reviewing these metrics. Once you have a baseline adjust this timeout value again

Chris Williams
  • 32,215
  • 4
  • 30
  • 68
  • Thanks for you reply. The timeout and memory has already been increased to 60 sec which is enough for a nodejs app to make a connection to mongo. When everything works fine then I get a response in milliseconds but in the timeout scenario, even 60 is less to do the processing. – Faisal May 16 '20 at 08:23
  • Hi have you reviewed your security groups / NACLs? – Chris Williams May 16 '20 at 08:24