I ended up using webpack to create a bundle per function. When using webpack set the library target to commonjs2.
entry: {
// save bundle is source location, this is required for serverless.yml
'./server/webpackbundle1': path.join(__dirname, './server/test1'),
'./server/webpackbundle2': path.join(__dirname, './server/test2'),
},
// use commonjs2 as output when creating a lambda bundle
output: {
libraryTarget: 'commonjs2',
filename: '[name].js'
},
target: 'node',
then in yml I’m setting the function handler to e.g. webpackbundle1.handler.
I’m not sure this is the best approach, but at least it works for what I need.
I sure it will. I was no aware I can specify a path in the lambda handler, and without that the handler is placed at root level, meaning you cannot include files above.
If instead you change the folder structure to something like this
Then, i just import libfile as usual inside any of the native services’ file and it works! When serverless zips the services it follows the links and actually creates a normal file, it works great.
I usually like to stay away from symbolic links. What is wrong with creating a shared folder and adding all the common code there? trying to figure out if symbolic links are serving a specific purpose?
how you managed to get serverless.yml working with the webpack outside of the folder?!
Do you have a main serverless.yml? How do you shared common config between them?
Also, how are you running the serverless-offline plugin?
I have a similar architecture, but using TS…