Second Layer not working
jwatts21 opened this issue · comments
how does one add a second layer? I created another layer named commonlibs, containing node_modules dependencies.
Both layers appear in the Lambda console with nodejs11 listed first. When I try to invoke the lambda get the following:
"errorType": "Error", "errorMessage": "Unable to import module 'handler'", "stackTrace": [ " at getHandler (/opt/bootstrap.js:138:13)", " at start (/opt/bootstrap.js:23:15)", " at Object.<anonymous> (/opt/bootstrap.js:18:1)", " at Module._compile (internal/modules/cjs/loader.js:723:30)", " at Object.Module._extensions..js (internal/modules/cjs/loader.js:734:10)", " at Module.load (internal/modules/cjs/loader.js:620:32)", " at tryModuleLoad (internal/modules/cjs/loader.js:560:12)", " at Function.Module._load (internal/modules/cjs/loader.js:552:3)", " at Function.Module.runMain (internal/modules/cjs/loader.js:776:12)", " at executeUserCode (internal/bootstrap/node.js:342:17)
this happen on the require('moment')
. I created my commonlibs layer with the following structure:
└── nodejs
├── node_modules
├── package-lock.json
└── package.json
Thanks
The formatting might have messed up a bit in your message so I can't see your exact layout.
NODE_PATH
includes /opt/nodejs/node_modules
– so as long as your modules are in nodejs/node_modules
in your zip, they should be unpacked in /opt
Does the layer work with the AWS-provided Node.js 8 runtime?
yes, the layer works Node.js 8 runtime, each layer works individually, when adding together the customlibs node_modules are not found. Also, using serverless framework version 1.36.0
ok, issue was that NODE_PATH was not set. I manually set it in the lambda console, everything works.
Hmmm, what ARN are you using for your layer?
NODE_PATH
should be set as per this commit: 7bcb6e4
using: arn:aws:lambda:us-east-1:553035198032:layer:nodejs11:3
was following the following tutorials:
https://statsbot.co/blog/a-crash-course-on-serverless-with-aws-running-node11-on-lambda/
Ah, please try the latest version (as mentioned in the README) and let me know if that works without needing NODE_PATH set manually:
arn:aws:lambda:us-east-1:553035198032:layer:nodejs11:5
I guess they might need to update their tutorials
Yep, works like a charm. My bad, should have looked more closely at the README. Thanks for your feedback and creating this project.
No probs, glad it worked for you in the end!