lambda 运行 节点是否支持 dynamodb-geo?

Is dynamodb-geo supported in lambda running Node?

我正在尝试按照此 article 创建一个简单的应用程序,但我无法让我的 Node Lambda 函数找到 dynamodb-geo 包。

这是我的资料:

const AWS = require('aws-sdk');
const ddbGeo = require('dynamodb-geo');

exports.handler = async (event, context) => {
  // Rest of the code here
};

Lambda 抛出的错误是:

START RequestId: 5d40d132-040f-447d-bd76-35c4cec0236a Version: $LATEST 2019-10-05T10:04:24.719Z undefined ERROR Uncaught Exception {"errorType":"Runtime.ImportModuleError","errorMessage":"Error: Cannot find module 'dynamodb-geo'","stack":["Runtime.ImportModuleError: Error: Cannot find module 'dynamodb-geo'"," at _loadUserApp (/var/runtime/UserFunction.js:100:13)"," at Object.module.exports.load (/var/runtime/UserFunction.js:140:17)","
at Object. (/var/runtime/index.js:45:30)"," at Module._compile (internal/modules/cjs/loader.js:778:30)"," at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)"," at Module.load (internal/modules/cjs/loader.js:653:32)"," at tryModuleLoad (internal/modules/cjs/loader.js:593:12)"," at Function.Module._load (internal/modules/cjs/loader.js:585:3)"," at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)","
at startup (internal/bootstrap/node.js:283:19)"]} END RequestId: 5d40d132-040f-447d-bd76-35c4cec0236a REPORT RequestId: 5d40d132-040f-447d-bd76-35c4cec0236a Duration: 1146.75 ms Billed Duration: 1200 ms Memory Size: 512 MB Max Memory Used: 35 MB Unknown application error occurred Runtime.ImportModuleError

关于可能发生的事情的任何线索?

你安装包了吗?

使用 npm 或纱线:npm install --save dynamodb-geoyarn add dynamodb-geo

文档:https://www.npmjs.com/package/dynamodb-geo

A​​WS Lambda 上唯一包含的包是 aws-sdk 包。其他所有内容(标准节点包除外)都需要与您的代码一起打包和上传。

有很多工具可以实现这一点:

您可以使用 Lambda layer 以便轻松导入外部包: