serverless project best practice

best practices for serverless projects

serverless project best practice

In this post I shall share the best practices for working with any serverless project.

The best practice that I want to mention here in this post is actually about “serverless project best practices for folder structure”.

The idea for structuring a project

How to achieve serverless project best practice with better folder structure

For achieving serverless project best practice, we should split our files into majorly two directories.Take a look at the below folder structure from our finished project.

serverless project best practice
serverless-project-best-practices-for-folder-structure folder structure
  1. Apis( for resources that may change on each deployment ):

    First I want to talk about Apis directory. Therefore I shall be creating the api resources. Because the apis are the ones that will be changing in definition for the most part of our project development lifecycle

    As a result the Apis stack is separated out and has a separate serverless.yml file. We will keep a separate serverless.yml file . Because we want to deploy this stack separately

    Now check the folder structure inside Apis directory

    api directory structure
    api directory structure

    Now on the image above you will directories like “events”, “templates” etc. Because I put functions into “templates” and http-events file into the “events” directory

    To summarise I must say that structuring your project in this way would actually help you in maintaining your project in the most optimal way

  2. resources( for resources that will remain constant for the lifetime of our project )

    The resources directory only has files that stays unchanged for the most part. For example, the Cognito pool does not need to be changed or updated frequently after it has been created

    I shall be creating a root API Gateway in future posts. And after that I shall attach all existing and new APIs to this API Gateway root

    Next I shall create an API Gateway authoriser. This will be attached to the API Gateway. And this is also a one time activity.

    Finally , I shall be putting all one time activities into the resources directory

    Now take a look at the modified and updated resources directory

    resources directory
    resources directory


Leave a Reply

Your email address will not be published. Required fields are marked *

Doubts? WhatsApp me !