Organizing Serverless Projects

Link to chapter - https://serverless-stack.com/chapters/organizing-serverless-projects.html

Great chapter. I could really use examples of a monorepo.

What are best practices if mulitiple services use the same dynamodo or Cognito setup.

How do you deploy multiple services with the same domain? Example - api.example.com?

I feel a chapter on this would be amazing. People are using monorepos but there are not examples outside of claiming you put severless.yml in different folders.

1 Like

Thats a great point. Thanks for feedback. I’m going to write a couple of chapters on these very shortly. But here is the general idea:

1 Like

Thank you so much @jayair this is a good start. Look forward to seeing the chapters. This guide has been indispensable and one of the best technology books/tutorials I have seen in my long career doing web development.

2 Likes

Thank you! I’m glad you’ve found it helpful!

The package.json (and the node_modules/ dir) are at the root of the repo. However, it is fairly common to have a separate package.json inside each service directory.

I think it would be interesting to expand on that a bit. The example provided is great but does not illustrate how to handle dependencies, and shared code between services which is a fairly common issue

That’s a good point. We’ve gotten a couple of requests for this in past. We’ll be updating this with a more detailed example.

How did you tackle the problem? By deploying every single service on aws, the common node_modules dir is not loaded

If anybody is looking for an example of how to handle your package.json in a monorepo app, we wrote about it here:

I’ll add a link to this in the chapter.

Hi. I managed to successfully follow your worderful tutorial with the proposed structure of the two repositories (resources and api). Now I am trying to replicate the structure in a project of my own and a little more complex. My project handles four Dynamo tables. The functions of each table may or may not require the user to be authenticated. On the other hand, there are functions that must be restricted for some particular users, which I do not know if the best way is to manage it though Cognito groups or roles. It is also unclear to me whether it is convenient for the four tables to share the same serverless.yml or rather to keep them independent. But really the most complex thing for me has been understanding how to handle the permissions of the functions for authenticated and unauthenticated users. I’m stuck there.

Well to start with you can create public APIs for your functions that don’t need auth. Remove the authorizer option from your serverless.yml: