What is the proper project structure to include 3rd party dependencies in NodeJS Lambda Layer?
Currently I have,
layer/nodejs/node_modules/module1
package.json
serverless.yml
When I do a sls deploy my Lambda Layer deploys w/ the ‘module1’ as I would expect, however any of the dependencies I have in package.json do not also deploy (moment in this example). What I am attempting to do is create a layer with ‘module1’ (our custom module) and all it’s dependencies already in the layer. Then when our devs build new Lambda Functions they can include ‘module1’ as a devDependency and when they sls deploy and use the custom layer the ‘module1’ dependency does not get packaged and uploaded as it’s already in the layer.
Is this possible? If not what’s the proper way to include 3rd party dependencies in a lambda layer for nodejs using serverless?
This is serverless.yml layer section,
layers:
authorization:
path: layer
compatibleRuntimes:
- nodejs8.10
and part of package.json,
"devDependencies": {
"serverless-webpack": "^5.2.0",
"webpack": "^4.29.0",
"webpack-node-externals": "^1.7.2"
},
"dependencies": {
"moment": "^2.23.0"
}
Thanks!