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

AWS Lambda Support Connect during "Init" Phase

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • 3.6.7, 4.4.1
    • 4.7.0
    • Lambda
    • 8
    • Not Needed

    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.

       

      Attachments

        1. events-with-resources.csv
          171 kB
        2. Screenshot 2022-04-06 at 15.03.56.png
          Screenshot 2022-04-06 at 15.03.56.png
          341 kB
        3. Screenshot 2022-04-06 at 15.04.40.png
          Screenshot 2022-04-06 at 15.04.40.png
          49 kB

        Issue Links

          Activity

            People

              durran.jordan@mongodb.com Durran Jordan
              anthony.cornetto@coxautoinc.com Anthony Cornetto
              Daria Pardue Daria Pardue
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: