Logo

dev-resources.site

for different kinds of informations.

Introducing multi-service deployments via Serverless Framework Compose

Published at
4/20/2022
Categories
serverless
serverlessframework
serverlesscompose
yaml
Author
goserverless
Author
12 person written this
goserverless
open
Introducing multi-service deployments via Serverless Framework Compose

Originally posted at Serverless

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.

With Serverless Framework Compose, it is possible to deploy all those Serverless Framework services via a single serverless deploy command. To do so, create a serverless-compose.yml file at the root:


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.

Note that it is also possible to deploy all services to a specific stage with the --stage option.

Solving service dependencies

Sometimes, services have dependencies between them. The output of one service (for example its API URL, a table name, a queue URL, etc.) might be used by another.

Passing outputs between dependencies no longer requires complex solutions with CloudFormation imports. In the serverless-compose.yml file, you can now pass outputs from one service to another:


Let’s break it down into 3 steps:
  1. ${products.tableName} will resolve to the "tableName" output of the "products" service.

The outputs of a Serverless Framework service are taken from its CloudFormation outputs. Here is how we can expose the “queueUrl” output in the products/serverless.yml config:

  1. Because of the dependency introduced by the variable, serverless deploy will automatically order deployments and deploy "products" first, and then "orders".

  2. The value will then be passed to the “orders” service as a parameter named “productsTableName”. Parameters can be referenced in Serverless Framework configuration:

    Compose is designed to integrate with existing serverless.yml features (CloudFormation outputs for outputs, Serverless Framework parameters for inputs). That way, using Compose does not require a huge rearchitecture of existing monorepositories.

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:

What’s next

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!

Originally published at https://www.serverless.com.

serverlessframework Article's
30 articles in total
Favicon
Build a highly scalable Serverless CRUD Microservice with AWS Lambda and the Serverless Framework
Favicon
Building Scalable Event Processing with Fan-out Pattern using the Serverless Framework
Favicon
Importing CloudFormation Resources to help fix deployments to Production
Favicon
How to add Amazon Cognito Auth to a Web App (part 4)
Favicon
Setting up for Serverless Development with AWS
Favicon
Basic Integration Testing with Serverless Framework
Favicon
Building an API with Ruby and the Serverless Framework
Favicon
How to use multiple runtimes in a single serverless microservice
Favicon
ShreyTheCray Interview: Serverless Framework & Cloud Explained
Favicon
Introducing multi-service deployments via Serverless Framework Compose
Favicon
Simple Serverless Scheduler
Favicon
Serverless (FaaS) vs. Containers — when to pick which?
Favicon
Provisioned Concurrency: What it is and how to use it with the Serverless Framework
Favicon
AWS Lambda Function URLs with Serverless Framework
Favicon
The ABCs of IAM: Managing permissions with Serverless
Favicon
AWS Lambda Destination Support
Favicon
Managing Stages and Environments in Serverless Framework
Favicon
Using API Gateway WebSockets with the Serverless Framework
Favicon
How to Create a REST API with Azure Functions and the Serverless Framework — Part 1
Favicon
How to deploy multiple micro-services under one API domain with Serverless
Favicon
How to Test Serverless Applications
Favicon
DynamoDB On-Demand: When, why and how to use it in your serverless applications
Favicon
The definitive guide to using Terraform with the Serverless Framework
Favicon
Serverless Framework example for Golang and Lambda
Favicon
Using SQS with AWS Lambda and Serverless
Favicon
Container Image Support for AWS Lambda
Favicon
Major changes to serverless-dotenv-plugin
Favicon
Using dotenv with the Serverless Framework
Favicon
API Gateway WebSocket APIs with the Serverless Framework
Favicon
Takeaways from using AppSync

Featured ones: