title: Connecting from AWS Lambda to MongoDB
body: <p>I'm working on a NodeJS project and using pretty common AWS setup it seems.  My ApiGateway receives call, triggers lambda A, then this lambda A triggers other lambdas, say B or C depending on params passed from ApiGateway.</p>
  
  <p>Lambda A needs to access MongoDB and to avoid hassle with running MongoDB myself I decided to use mLab. ATM Lambda A is accessing MongoDB using NodeJS driver. 
  Now, not to start connection with every Lambda A execution I use connection pool, again, inside of Lambda A code, outside of handler I keep connection pool that allows me to reuse connections when Lambda A is invoked multiple times.
  This seems to work fine.
  However, I'm not sure how to deal with connections when Lambda A is invoking Lambda B and Lambda B needs to access mLab's MongoDB database. </p>
  
  <ol>
  <li>Is it possible to pass connection pool somehow or Lambda B would have to keep its own connection pool?</li>
  <li>I was thinking of using <a href="https://docs.mlab.com/data-api/" rel="nofollow noreferrer">mLab's Data API</a> that exposes most of the operations of MongoDB driver and so I could use HTTP calls e.g. GET and POST to run commands against database. It seems similar to <a href="https://restheart.org/" rel="nofollow noreferrer">RESTHeart</a> it seems.</li>
  </ol>
  
  <p>I'm leaning towards option 2 but on <a href="https://docs.mlab.com/data-api/" rel="nofollow noreferrer">mLab's Data API</a> it clearly states to avoid using REST api unless cannot connect using MongoDB driver directly:</p>
  
  <hr>
  
  <blockquote>
    <p>The first method—the one we strongly recommend whenever possible for
    added performance and functionality—is to connect using one of the
    available MongoDB drivers. You do not need to use our API if you use
    the driver. The second method, documented in this article, is to
    connect via mLab’s RESTful Data API. Use this method only if you
    cannot connect using a MongoDB driver.</p>
  </blockquote>
  
  <hr>
  
  <p>Given all this how would it be best to approach it? 1 or 2 or is there any other option I should consider? </p>