Serverless Framework Compose: Multiframework Deployment
Deploying multiple services in a monorepository is a common pattern in larger teams. Serverless Framework Compose simplifies the deployment and orchestration of these services by offering:
- Parallel deployment of multiple services
- Ordered deployment of services
- Support for deploying different types of services (e.g., Traditional, SAM, CloudFormation) together
- Sharing outputs between services
- Running commands across multiple services
In this example, we demonstrate how to use Serverless Compose to deploy three types of services together:
- AWS CloudFormation Service: Deploys shared resources with outputs that are referenced by the other services.
- Serverless Framework Traditional Service
- AWS SAM Template Service
The AWS CloudFormation service is deployed first to create shared resources, followed by the parallel deployment of the Traditional and AWS SAM services.
This example also illustrates how to use Serverless Variables with Serverless Compose for organizing and structuring your application, as well as managing different stages.
For more information about Serverless Compose, please see the Serverless Compose docs
For more information about using AWS SAM and or AWS CloudFormation templates with the Serverless Framework, please see the AWS SAM/CFN docs
For more information about Serverless Variables, please see the Serverless Variables docs
Usage
Deployment
Run the following command from the root of this example (where serverless-compose.yml lives):
serverless deploy
Compose reads the dependency graph implied by the ${service.Output} variable references in serverless-compose.yml and deploys the three sub-stacks in the correct order:
shared-resources-example(cloudformation/template.yml) deploys first. It creates a shared DynamoDB table and exposes its name via theTableNamestack output.traditional(traditional/serverless.yml) andsam(sam/template.yml) deploy next, in parallel, since both only depend onshared-resources-example. Each receives the shared table name through thetableNameparam, which Compose resolves from${shared-resources-example.TableName}.
Stage-specific values (such as the domain param) come from the stages block at the top of serverless-compose.yml; deploy to a specific stage with serverless deploy --stage prod.
Removal
serverless remove
This tears down the services in reverse dependency order (traditional and sam first, then shared-resources-example).