Open source

New Open Source AWS Lambda function proxy, for MongoDB

Today I’m releasing an open source AWS Lambda function that serves as a MongoDB connection proxy. (aka Proxy)

It uses MongoDB native driver, Lambda & Secrets Manager.

With Proxy, your Lambda functions don’t need to establish its own database connection Instead, they will invoke “Proxy”, sending the query parameters. Once invoked, the Proxy will run the query using the standard MongoDB Node.js driver, and reply back with the query results.

This will help you to reduce database stress, idle connections, etc. It has support for find, update, delete, aggregate, etc.

See webiny’s blog to understand more about the problem that Proxy solves.

Check the source code and how to start using it:

Working code example for your Javascript projects:

  const dbQuery = {
    collection: 'users',
    op: 'findOne',
    query: {
      name: 'Jon'
    options: {
      fields: { email: 1 },

  return new Promise((resolve, reject) => {
      var params = {
          FunctionName: 'myDbProxyFunctionName',
          InvocationType: 'RequestResponse',
          LogType: 'None',
          Payload: JSON.stringify(dbQuery)
      lambda.invoke(params, (err, result) => {
        if (err) return reject(err)
        const response = JSON.parse(result.Payload)
        if (!response.success) return reject({
          reason: response.reason,
          error: response.error
        return resolve(response.result)

  // Example outputs:
  // Resolves: { email: '' }
  // Resolves: [ { email: '' } ]
  // Rejects: { reason: 'Unrecognized pipeline stage name: \'$matcsh\'', error: '......' }
  // Rejects: { reason: 'failed to connect to server...', error: '......' }

Leave a Reply

Your email address will not be published. Required fields are marked *