For one of the projects at Nggawe Nirman, we were having multiple services in microservices architecture and we were using API gateway and lambda for our services.
We were having our services in Monorepo, and deployment was done by automatically zipping the artifacts and pushing it to s3, but as we started using different features for API gateway, lambda and other services the setup task became manual and started taking too much time that is when we decided to use Serverless framework for our deployments.
As we were having our projects in Monorepo, our project structure looked something like this.
The common package holds all the common utils, libraries which will be shared across all the services and helps to maintains common standards across different services and promotes shared learning accross services.
Each service will have there serverless.yml for the deployments at the root directory. Example serverless_app1 service will have app1_serverless.yml at the root directory.
serverless config for service app1 “app1_serverless.yml” will only include common and serverless_app1 packages, and it will exclude other services as shown in the image above.
To deploy a particular service, we call below command from the root directory of our monorepo
serverless deploy --config app1_serverless.yml
It generates the state file in .serverless directory, during deployments we manage the state file for each service and push it to s3.
Your deployment pipeline for each service will look something like this.
- Pull state file from s3 for the given service.
- serverless deploy — config serverless_yml_for_given_service.yml.
- Push and replace the state file on s3.
As of now, this is serving us well, Please let us know if you think if we can improve this or if you have any better strategy to deploy serverless projects in Monorepo.
You can connect to me here
The latest Tweets from sohit kumar (@ksohit). swiss knife, solves problem using technology