I’ve got a workflow where a few of the activities need to reach out to MongoDB and modify collections. We’ve got applications on lambda and we needed to make sure we initialized the connection outside the handler to make sure we didn’t reconnect on every invocation. Does the same principal apply for Activities? If I make a DB connection outside of the exported activity, will it hold that connection open for future invocations?
Below is a snippet of a conversation between a MongoDB rep and I.
Do not connect to Mongo on Lambda invocation. Doing so causes the driver to create a new database connection with each function call. This causes high connection creation and since MongoDB authenticates users by hashing the username and password almost 15k times to ensure that brute force attacks cannot work, connection creation is highly expensive.