Home / Companies / MongoDB / Blog / Post Details
Content Deep Dive

Optimizing AWS Lambda With MongoDB Atlas & NodeJS

Blog post from MongoDB

Post Details
Company
Date Published
Author
Raphael Londner
Word Count
986
Company Posts That Month
2
Language
English
Hacker News Points
-
Summary

Optimizing AWS Lambda performance requires understanding its container technology and caching mechanisms. When invoking a Lambda function, there's an initial penalty hit due to bootstrapping a new container, but subsequent calls within 5 minutes can reuse the same container, saving time. To optimize performance, declare the database connection object outside the handler method, as this allows for reusing the connection across calls. Additionally, set `context.callbackWaitsForEmptyEventLoop` to `false` in Node.js Lambda functions and try to reuse the database connection using `MongoClient.connect(Uri)` only if it's not null and connected. Most importantly, do not close the database connection to allow it to be reused by subsequent calls. By following these steps, developers can significantly reduce the execution time of their Lambda functions.

Trends Found in this Post
Trend Post Mentions Total Month Mentions Posts Companies MoM
Serverless 36 134 18 12 -27%