10

My team is in the process of creating a project which follows the serverless architecture, we are using AWS Lambda, NodeJS, and Serverless framework. The application will be a set of services each one will be handled as a separate function.

I found examples combining multiple functions under the same project then using cloud formation to deploy all at once, but with some defects we don't want, like having resources of different modules deployed for each lambda function, which will cause some redundancy and if we want to change one file it will not be reflected in all lamda functions as it's local to the hosting lamda function

https://github.com/serverless/examples/tree/master/aws-node-rest-api-with-dynamodb

My question: do you know the best way to organize a project containing multiple functions, each one has it's separate .yaml and configurations with the ability to deploy all of them when needed or specify selective updated functions to be deployed?

John Smith
  • 7,243
  • 6
  • 49
  • 61
emad omara
  • 498
  • 2
  • 5
  • 16
  • Can you elaborate a little on why using one yaml file containing several functions doesn't suite you? This will centralize you deployment and really make your life easier. What defects did you encounter? – Gal Bashan Feb 15 '18 at 10:58
  • @GalBashan thanks for your comment , I updated the post with my concern also we need to have it following the microservices way by isolating each service alone and don't have coupling between them – emad omara Feb 15 '18 at 11:18
  • Looking at the issues you described, there are solutions while still using serverless and 1 yaml file: 1. You can set a reasource to a specific function, not the entire project 2. You can deploy a single function using sls deploy function, so a change in one file wont cause a dwployment to all Is that helpful or am i missing something? – Gal Bashan Feb 15 '18 at 11:23

1 Answers1

14

I think I found a good way to do this in a way like the one mentioned here : https://serverless.readme.io/docs/project-structure

I created a service containing some Labmda functions , each one is contained within a separate folder , also I had a lib folder on the root level containing all the common modules that can be used in my Lambda functions .

So my Structure looks like :

Root ---
      functions----
               function1
               function2
      libs---
      tests--
      resources 
serverless.yml (root level)

and in my yml file I'm pointing to Lamdas with relative paths like :

functions:
  hello1:
    handler: functions/function1/hello1.hello

Now I can deploy all functions with one Serverless command , or selectively deploy the changes function specificity

and the deployed Lamda will only contain the required code

Community
  • 1
  • 1
emad omara
  • 498
  • 2
  • 5
  • 16