We are excited to announce Serverless Framework Compose: a new feature enabling you to deploy multiple services in one command, in parallel, or ordered by dependencies!
To use this new feature, upgrade the serverless CLI to v3.15 or greater and follow the guide below.
Composing multiple Serverless Framework services
Deploying multiple services in a monorepository is a very common pattern across larger teams. Orchestrating these deployments can become painful.
Let's take the following (simple) example project:
Our application contains 2 services. Each service can be deployed separately by running serverless deploy in each folder.
The new "serverless-compose.yml" configuration file references the existing Serverless Framework projects:
As you can see above, each existing Serverless Framework service is referenced via a relative path. When running "serverless deploy" in the root directory, Compose will deploy both services ("products" and "orders") in parallel.
While Compose triggers the deployment, each deployment runs as usual, in the exact same conditions as a traditional Serverless Framework deployment. This was designed so that introducing Compose in an existing project would have no side-effect.
Setting dependencies without variables
Using variables allows us to exchange values and order deployments. It is also possible to order deployments without variables via the "dependsOn" feature:
In the example above, the "products" service will be deployed before "orders". This can be useful in scenarios where a service interacts with another and we want to make sure API or schema changes are deployed in a specific order.
Global commands and service commands
An interesting benefit of grouping multiple services behind a single configuration is that we can run one command in all services at once. For example:
We can also run service-specific commands without having to change directories:
Serverless Framework now lets you compose services to orchestrate their deployments.
Services can integrate together via variables and are deployed in order based on their dependencies.
There is a lot more to Serverless Framework Compose, head over to the documentation to learn more and get started.
We are also exploring exciting ideas to improve Compose in the near future, like:
- accelerating deployments for services that haven't changed
- deploying only specific services via a filter flag
- multi-region deployments
Get involved in the Serverless Framework repository to discuss these ideas!