简体   繁体   中英

Connection timeout between AWS Lambda function and MongoDB

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM