如何从无服务器框架中的aws lambda调用mongodb函数?

我一直在观看像这样的无服务器框架上的video教程,并根据我收集的信息,似乎使用框架是pipe理aws lambda函数的最有效的方法之一。 在上面的video链接中,给出了一个使用lambda函数连接到DynamoDB表的示例,然后将其保存。 我需要做的是连接到一个MongoDB表,然后从中获取数据。

我只find了在无服务器上使用DynamoDB但在MongoDB中没有的例子。 我认为这个过程应该是相似的,但似乎并非如此。 我发现这个教程,但它不使用无服务器框架。

下面是在无服务器框架中从lambda连接并保存到Dynamo数据库表的示例:

const uuidV1 = require('uuid/v1'); const AWS = require('aws-sdk'); const promisify = require('es6-promisify'); const _ = require('lodash'); const dynamo = new AWS.DynamoDB.DocumentClient(); module.exports.saveUserToDatabase = function(userId, coffeeType, coffeeSize) { console.log('saveUserToDatabase'); const item = {}; item.drink = coffeeType; item.size = coffeeSize; item.userId = userId; return saveItemToTable('coffee-user-table', item); }; 

以下片段是用于使用名为lambda-local的npm包连接到MongoDB Atlas数据库的代码:

 var MongoClient = require('mongodb').MongoClient; let atlas_connection_uri; let cachedDb = null; exports.handler = (event, context, callback) => { var uri = process.env['MONGODB_ATLAS_CLUSTER_URI']; if (atlas_connection_uri != null) { processEvent(event, context, callback); } else { atlas_connection_uri = uri; console.log('the Atlas connection string is ' + atlas_connection_uri); processEvent(event, context, callback); } }; function processEvent(event, context, callback) { console.log('Calling MongoDB Atlas from AWS Lambda with event: ' + JSON.stringify(event)); } 

有没有一种方法来实现用于MongoDB Atlas和npm lambda-local的逻辑,除了无服务器框架?