使用 Sharp 库运行 AWS Lambda 函数时出现问题

Ele*_*ark 3 node.js aws-lambda sharp aws-amplify

我按照 AWS 研讨会 ( https://amplify-workshop.go-aws.com/70_generate_thumbnails/10_creating_a_photo_processor_lambda.html ),通过 aws-amplify CLI 创建了一个 lambda 函数。似乎某个地方的 Node.js 版本存在冲突。

我认为 Sharp 库是问题所在,因此我尝试将版本更改为最新版本,看看是否会起到任何作用,但它没有解决问题。

云观察错误日志:

module initialization error: Error
was compiled against a different Node.js version using
NODE_MODULE_VERSION 67. This version of Node.js requires
NODE_MODULE_VERSION 57. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).
at Object.Module._extensions..node (module.js:681:18)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/var/task/node_modules/sharp/lib/constructor.js:10:15)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
Run Code Online (Sandbox Code Playgroud)

我相信有一个简单的修复方法,但我不确定问题的根源在哪里。谢谢。

小智 5

安装 Sharp 时使用您的 aws lambda 节点版本。

rm -rf node_modules/sharp
npm install --arch=x64 --platform=linux --target=10.4.1 sharp
Run Code Online (Sandbox Code Playgroud)