Reputation: 633
I created a lambda function through the aws-amplify CLI by following an AWS workshop (https://amplify-workshop.go-aws.com/70_generating_thumbnails/10_creating_a_photo_processor_lambda.html). Seems that there is a problem with conflicting versions of Node.js somewhere.
I believe that the sharp library is the problem, so I have tried to change the version to the latest to see if that would do anything, but it did not fix the issue.
CloudWatch error log:
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)
I believe there is a simple fix, but I am unsure where the source of the problem lies. Thank you.
Upvotes: 3
Views: 5959
Reputation: 119
I know this question is old. I had the same trouble and discovered the issue is when we build the project (layer) in windows machine and try to run it in lambda. The dependencies built in Linux and Windows environments are different.
Try building & creating the zip file in a linux environment. That should fix your issue.
Upvotes: 2
Reputation: 4678
The following worked for me:
npm_config_arch=x64 npm_config_platform=linux npm install sharp
For some reason, arguments did not work.
Upvotes: 1
Reputation: 1299
Use your aws lambda node version when installing sharp.
rm -rf node_modules/sharp
npm install --arch=x64 --platform=linux --target=10.4.1 sharp
Upvotes: 6
Reputation: 1661
Looks like you have built your node_modules
using lambda incompatible version of Node.js
. Lambda only supports Node.js 6.10 and 8.10.
Try changing your local node version to 8.10
, remove node_modules
, npm install
, bundle folder including node_modules
and upload to lambda. This should work.
Upvotes: 3