I’m new to serverless, serverless framework and AWS too, so I’m sorry if something isn’t clear.
I was building a service on AWS in a monorepo (node.js + lerna) with some lambdas and I’m reading all around the web people organizing their projects and serverless files in different ways, but I haven’t figured out which would be the best way to do so (at least for my case).
I’m creating a series of lambdas (let’s say 2) and an API Gateway to serve some end points.
I have a couple of shared resources: a DynamoDB and an SQS queue to invoke one of the two lambdas.
All of this is made with a monorepo (node.js) and a series of packages, some of which are shared among the lambdas and some of which aren’t.
I’m now seeing two possible ways to organize the serverless configuration, both of which have their downsides:
- Every lambda has it’s own serverless.yml file. Maybe there are some shared yaml file to avoid duplicating some configurations.
- Faster deployment (I can deploy a single lambda whenever I want)
- I can easily run serverless-offline and serverless-offline-sqs plugins in the related lambdas, and debug with them.
- I don’t have a single CloudFormation stack, but everything is disconnected from the rest… leading to possible inconsistencies.
- I still have to duplicate the usage of those configurations inside the serverless files
- Have a common serverless.yml file in the root folder. This common serverless is the one used to deploy. Other yaml files can be used for configurations and/or for declaring the function specification. They are all referenced in the common serverless file.
- Single CloudFormation stack.
- Very easy to read serverless file too: all my stack is in that same serverless file. I don’t have to duplicate the root definition of the serverless file for every lambda.
- Actually can deploy single lambda here too with sls deploy function (actually this should only be used when developing).
- Can’t figure out how am I supposed to run in the single lambda serverless-offline and serverless-offline-sqs. I can only run it from the root folder, since the only serverless file is out of the other packages, but running the debug from out of the packages looks so bad compared to running it inside a single package/lambda.
To wrap it up I guess the question still is:
Do I have a single serverless file in the root folder (and optionally some configuration yaml files here and there) or do I keep them separate for each lambda?
Also, is there a way to avoid those CONS I talked about?
And finally, since you guys definitely know more than me, am I missing something else that should lead me towards one way or the other? (or maybe a third option I’ve completely missed)
Thank you guys in advance for your time and your patience in reading this far.