New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Which is best folder/file structure to organize multiple functions of service in v1.0 #2372
Comments
I made
serverless.yml setting as follow: functions:
function1:
handler: src/function1.handler
events:
- http:
path: function1
method: get
- http:
path: function1
method: post
function2:
handler: src/function2.handler
events:
- http:
path: function2
method: get
- http:
path: function2
method: post
function3:
handler: src/function3.handler
events:
- http:
path: function3
method: get
- http:
path: function3
method: post |
@horike37 thanks for reply,how you are dealing with include/exclude with function because some node module only require for specific function,we cant upload everything with single function zip,if you will check your function folder after download from aws lambda console you will see some unnecessary file in zip like node module or other function's file |
I see. How about bellow? Serverless project tree
serverless.yml settingpackage:
individually: true
functions:
function1:
handler: function1/index.handler
package:
exclude:
- function2/**
function2:
handler: function2/index.handler
package:
exclude:
- function1/** https://serverless.com/framework/docs/guide/packaging/ But Every time you add a function, adding exclude file/folder the statements in the For example
functions:
function1:
handler: function1/index.handler
package:
include:
- function1/**
- node_modules/RequireModule1
- node_modules/RequireModule2
function2:
handler: function2/index.handler
package:
include:
- function2/**
- node_modules/RequireModule3 |
yes this was main issue in serverless
this is little problematic because it is not good to make node_modules in each folder.we can make common Your approach related |
@pmuens @flomotlik |
I think having a per-function directory (each with it's own |
@horike37 do you know how your suggestion works with plugins? I'm trying to structure my project like:
and within my
but am getting the error: |
Running into the same scenario that I want to use include inside each function to avoid bloat in the artifact. |
with functions:
function1:
handler: function1/index.handler
package:
include:
- function1/**
- node_modules/RequireModule1
- node_modules/RequireModule2
function2:
handler: function2/index.handler
package:
include:
- function2/**
- node_modules/RequireModule3 Do you strictly use npm2 or is there a way to use npm3 (which has a flat structure)? |
+1 on adding |
I'm doing the following and I like it thus far:
|
Checkout this plugin https://github.com/doapp-ryanp/serverless-plugin-browserify which handles efficient bundling for you. My folder structure is like this:
In each
The browserfy plugin will create the optimal package using only the dependencies required. |
Closing this issue since we have some great examples already. Feel free to continue the discussion. Another good place to find some inspiration is the official Serverless Examples repository: https://github.com/serverless/examples |
I didn't really see in the examples from the link above any use of node_modules at all. Some official guidance regarding this topic would be great. |
Hey @DmitryEfimenko thanks for the response. You might also want to look at this list of real world projects for inspiration: https://github.com/JustServerless/awesome-serverless/blob/master/README.md#projects--services |
@pmuens I'm using serverless-webpack and I haven't seen any project in the examples that optimizes for each function to only contain the modules it needs and no more. I'm fine with either a central |
@btburton42 serverless-webpack v3 will support individual packaging, i.e. you enable |
@HyperBrain thanks for the quick reply. I'll give v3 a spin tomorrow and post any errors to your PR thread here serverless-heaven/serverless-webpack#175 |
@horike37 I like your second example, except when deployed the handler is
It would be expecting just |
A question on this, would this structure mean your services are more prone to cold starts? If all of your CRUD operations were in a single file I was told this would mean the container will have more chance of staying up meaning a fast start time. |
This is related to the serverless
v1.0
. I am opening this for discussion only.How we can organize multiple function in proper manner
2,
serverless.yml
sampleWhich is best approach to do above things ?
The text was updated successfully, but these errors were encountered: