Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-4140

Investigate NODE-4139 - AWS Lambda Support Connect during "Init" Phase

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
    • 3
    • Not Needed

      NODE-4139 Description

      What problem are you facing?

      We are attempting to build our Lambdas using NodeJS and ES Modules instead of Common JS.  The main reason for this is to support top level await.  This is working well.  If we use Top Level Await in order to `MongoClient.connect` and keep the promise, everything seems to connect and work. 

      We are using provisioned concurrency with our lambdas.

      Our expectation is that the connection would be good and our first actual invocation would not need to suffer the pain of creating a connection.  Currently, a connection to our Mongo Atlas instance seems to take ~250ms in us-east-1 and ~800ms in us-west-2 (since the primary is in us-east-1).  Our thought is if this can happen during the "init" phase, we would be able to move that time away from the invocations giving our app a performance boost.

      After the first invocation, subsequent invocations do benefit from an existing connection and gain the benefit.

      What driver and relevant dependency versions are you using?

      We had problems using mongodb 3.6.7 and mongodb 4.4.1

      Steps to reproduce?

      • Create a lambda
      • use the following code in the GLOBAL portion of the lambda (not inside the handler)

      ```const client = new MongoClient(process.env.MONGODB_URI);

      const promise = await client.connect();```

      • In the handler, use the promise in order to write a query or any other operation against mongo.

       

      You will notice a connection being formed again on the first invocation within the handler.

       

            Assignee:
            durran.jordan@mongodb.com Durran Jordan
            Reporter:
            dbeng-pm-bot PM Bot
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: