Skip to content

Commit fd113f5

Browse files
authored
Merge pull request #797 from serverless/compose-multiframework-docs
docs(compose): update docs
2 parents bbd0cb6 + 8ef6b01 commit fd113f5

File tree

11 files changed

+105
-63
lines changed

11 files changed

+105
-63
lines changed

compose-multiframework/README.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Serverless Framework Compose: Multiframework Deployment
2+
3+
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:
4+
5+
1. Parallel deployment of multiple services
6+
2. Ordered deployment of services
7+
3. Support for deploying different types of services (e.g., Traditional, SAM, CloudFormation) together
8+
4. Sharing outputs between services
9+
5. Running commands across multiple services
10+
11+
In this example, we demonstrate how to use Serverless Compose to deploy three types of services together:
12+
13+
1. AWS CloudFormation Service: Deploys shared resources with outputs that are referenced by the other services.
14+
2. Serverless Framework Traditional Service
15+
3. AWS SAM Template Service
16+
17+
The AWS CloudFormation service is deployed first to create shared resources, followed by the parallel deployment of the Traditional and AWS SAM services.
18+
19+
This example also illustrates how to use Serverless Variables with Serverless Compose for organizing and structuring your application, as well as managing different stages.
20+
21+
For more information about Serverless Compose, please see the [Serverless Compose docs](https://www.serverless.com/framework/docs/guides/compose)
22+
23+
For more information about using AWS SAM and or AWS CloudFormation templates with the Serverless Framework, please see the [AWS SAM/CFN docs](https://www.serverless.com/framework/docs/guides/sam)
24+
25+
For more information about Serverless Variables, please see the [Serverless Variables docs](https://www.serverless.com/framework/docs/guides/variables)

compose-multiframework/cloudformation-compose-service/template.yml

-20
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# This is a shared CloudFormation service that is being referenced by the traditional and SAM services.
2+
# This is a good place to put shared resources like DynamoDB tables, S3 buckets, etc.
3+
# that will be used by other services.
4+
5+
AWSTemplateFormatVersion: "2010-09-09"
6+
7+
Resources:
8+
SharedTable:
9+
Type: "AWS::DynamoDB::Table"
10+
Properties:
11+
# We are using the parameter passed down from Serverless Compose, and the current stage.
12+
# To construct the final table name.
13+
TableName: ${param:tableNamePrefix}-${sls:stage}
14+
AttributeDefinitions:
15+
- AttributeName: "Id"
16+
AttributeType: "S"
17+
KeySchema:
18+
- AttributeName: "Id"
19+
KeyType: "HASH"
20+
ProvisionedThroughput:
21+
ReadCapacityUnits: 5
22+
WriteCapacityUnits: 5
23+
24+
# We are outputting the table name so that other services can reference it.
25+
Outputs:
26+
TableName:
27+
Value: !Ref SharedTable

compose-multiframework/sam-compose-service/handler.js

-9
This file was deleted.

compose-multiframework/sam/handler.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
exports.handler = async (event) => {
2+
return {
3+
service: "sam",
4+
tableName: process.env.TABLE_NAME,
5+
domain: process.env.DOMAIN,
6+
};
7+
};

compose-multiframework/sam-compose-service/template.yml renamed to compose-multiframework/sam/template.yml

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
AWSTemplateFormatVersion: "2010-09-09"
22
Transform: AWS::Serverless-2016-10-31
3-
Description: >
4-
sam-app
5-
6-
Sample SAM Template for sam-app
73

84
Globals:
95
Function:
@@ -18,8 +14,10 @@ Resources:
1814
Runtime: nodejs20.x
1915
Environment:
2016
Variables:
17+
# We are using the output of the shared resources CloudFormation template
18+
# that is passed down from Serverless Compose, and the staged param "domain".
2119
TABLE_NAME: ${param:tableName}
22-
STAGE_LABEL: ${param:stageLabel}
20+
DOMAIN: ${param:domain}
2321
Architectures:
2422
- x86_64
2523
Events:
+32-18
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,45 @@
1-
# This example shows how to use Serverless Compose
2-
# to compose 3 services together:
3-
# - A CloudFormation service
4-
# - A traditional Serverless Framework service
5-
# - A SAM service
6-
# It specifically shows how to pass parameters between services
7-
# and how to reference outputs from one service in another service.
1+
# Serverless Framework can deploy multiple types of templates:
2+
# 1) Traditional Serverless Framework templates
3+
# 2) AWS Cloudformation Templates
4+
# 3) AWS SAM Templates.
5+
# This is useful if your organization is using these different templates and wants one tool to standardize around.
6+
# Here, we use Serverless Framework Compose (serverless.com/framework/docs/guides/compose) to deploy three different template types in a single deploy command.
7+
# Deployments happen in parallel by default. You can also share outputs from one Service to another, across template types.
8+
# In this case, Compose will auto-determine the correct order to deploy each Service.
89

910
stages:
1011
default:
1112
params:
12-
stageLabel: "testing"
13+
domain: "serverless.dev"
1314
prod:
1415
params:
15-
stageLabel: "production"
16+
domain: "serverless.com"
1617

1718
services:
18-
cloudformation-compose-service:
19-
path: cloudformation-compose-service
19+
# Framework: AWS CloudFormation
20+
# The service name here will be used as the underlying cloudformation stack name.
21+
# Make sure it’s unique so it doesn’t collide, and accidently update another stack.
22+
# If you change it, make sure you update the references in other services.
23+
shared-resources-example:
24+
path: cloudformation
2025
params:
21-
tableNamePrefix: compose-shared-table
26+
# We are passing a simple string parameter to the CloudFormation template.
27+
# If you open the template file, you will see that we reference it with ${param:tableNamePrefix}
28+
tableNamePrefix: shared-table
2229

23-
traditional-compose-service:
24-
path: traditional-compose-service
30+
# Framework: Serverless Framework Traditional
31+
traditional:
32+
path: traditional
2533
params:
26-
tableName: ${cloudformation-compose-service.TableName}
34+
# We are passing a reference to the shared CloudFormation stack output to the traditional service.
35+
# The shared CloudFormation stack is deployed first, and the output is passed to this service.
36+
tableName: ${shared-resources-example.TableName}
2737

28-
sam-compose-service:
29-
path: sam-compose-service
38+
# Framework: AWS SAM
39+
sam:
40+
path: sam
3041
params:
31-
tableName: ${cloudformation-compose-service.TableName}
42+
# We do the same here, passing the shared CloudFormation stack output to the SAM service.
43+
# Both the traditional and SAM services will be deployed in parallel.
44+
# As they both depend on the same shared service.
45+
tableName: ${shared-resources-example.TableName}

compose-multiframework/traditional-compose-service/handler.js

-9
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
exports.handler = async (event) => {
2+
return {
3+
service: "traditional",
4+
tableName: process.env.TABLE_NAME,
5+
domain: process.env.DOMAIN,
6+
};
7+
};

compose-multiframework/traditional-compose-service/serverless.yml renamed to compose-multiframework/traditional/serverless.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
service: traditional-compose-service
1+
service: traditional
22

33
provider:
44
name: aws
@@ -12,5 +12,7 @@ functions:
1212
path: /
1313
method: get
1414
environment:
15+
# We are using the output of the shared resources CloudFormation template
16+
# that is passed down from Serverless Compose, and the staged param "domain".
1517
TABLE_NAME: ${param:tableName}
16-
STAGE_LABEL: ${param:stageLabel}
18+
DOMAIN: ${param:domain}

0 commit comments

Comments
 (0)