Skip to content

Commit ad16b0a

Browse files
authored
fix: add state to the config schema (#12909)
1 parent 5fea01a commit ad16b0a

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

docs/guides/state.md

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
<!--
22
title: 'Serverless Framework State'
3-
description: 'Learn how to manage state in Serverless Framework Compose.'
3+
description: 'Learn how to manage state in Serverless Framework'
44
short_title: Serverless Framework State
55
keywords:
66
[
77
'Serverless Framework',
8-
'serverless-compose',
98
'state management',
109
'S3 state',
1110
'service state',
@@ -20,28 +19,33 @@ keywords:
2019

2120
# Serverless Framework State
2221

23-
Serverless Framework Compose allows for the orchestration and deployment of multiple services.
22+
Serverless Framework allows for the orchestration and deployment of multiple services.
2423
A crucial aspect of this is managing the state of each service, which includes storing outputs and other runtime information necessary for the correct operation of services.
2524
This guide covers how to set up and manage state using AWS S3 and AWS SSM.
2625

26+
**Note:** Starting from Serverless Framework v4.4.8, the state is saved for all services, not just when using Compose.
27+
This ensures seamless transitions between Compose and non-Compose deployments without losing state information.
28+
2729
## State Management Overview
2830

29-
State management in Serverless Framework Compose is crucial for:
31+
State management in Serverless Framework is crucial for:
3032

3133
- **Storing Service Outputs**: Save outputs from deployments to share them across services.
3234
- **Ensuring Consistency**: Maintain the state of services across deployments, ensuring that each service can access the necessary data for its operation.
3335
- **Handling Dependencies**: Automatically resolve dependencies between services by referencing shared state.
3436

35-
Serverless Framework Compose uses AWS S3 to store the state of services and AWS SSM (Systems Manager) to track the location of the state storage.
37+
Serverless Framework uses AWS S3 to store the state of services and AWS SSM (Systems Manager) to track the location of the state storage.
3638

3739
## Zero-Configuration Setup
3840

39-
The easiest way to manage state in Serverless Framework Compose is through its default, zero-configuration setup. When you don’t specify any state configuration, Serverless Framework Compose automatically handles everything for you.
41+
The easiest way to manage state in Serverless Framework is through its default, zero-configuration setup.
42+
When you don’t specify any state configuration, Serverless Framework automatically handles everything for you.
43+
To specify custom state management settings, for example, if you want to use an existing S3 bucket, see the [Custom State Configuration](#custom-state-configuration) section.
4044

4145
### How It Works
4246

43-
1. **Automatic S3 Bucket Creation**: If no state configuration is provided in your `serverless-compose.yml`, Serverless Framework Compose automatically creates an S3 bucket to store the state.
44-
2. **SSM Parameter Store**: The name and region of the automatically created S3 bucket are stored in AWS SSM Parameter Store under the parameter `/serverless-framework/state/s3_bucket`. This parameter contains a JSON object with the following keys:
47+
1. **Automatic S3 Bucket Creation**: If no state configuration is provided in your `serverless.yml` or `serverless-compose.yml`, Serverless Framework automatically creates an S3 bucket to store the state.
48+
2. **SSM Parameter Store**: The name and region of the automatically created S3 bucket are stored in AWS SSM Parameter Store in `us-east-1` AWS region, under the parameter `/serverless-framework/state/s3-bucket`. This parameter contains a JSON object with the following keys:
4549

4650
- `bucketName`: The name of the S3 bucket.
4751
- `bucketRegion`: The AWS region where the bucket is located.
@@ -51,9 +55,9 @@ The easiest way to manage state in Serverless Framework Compose is through its d
5155
**Note**: To create the default state bucket, you must have the necessary permissions to put SSM parameters and create versioned S3 buckets.
5256
If you don’t have these permissions, you can set up a [custom state configuration](#custom-state-configuration) to use an existing S3 bucket.
5357

54-
### Example
58+
### Using State with Serverless Framework Compose
5559

56-
Assume you have the following serverless-compose.yml with two services:
60+
Assume you have the following configuration with two services:
5761

5862
```yaml
5963
services:
@@ -98,7 +102,8 @@ making it easy to manage and deploy services with complex interdependencies.
98102
## Custom State Configuration
99103

100104
While the zero-configuration setup is convenient, there may be situations where you want to customize how and where the state is stored.
101-
If you require this level of customization, you can specify custom state management settings in your `serverless-compose.yml`.
105+
If you require this level of customization,
106+
you can specify custom state management settings in your `serverless.yml` or `serverless-compose.yml`.
102107
Here’s how you can do it:
103108

104109
### Using a Custom S3 Bucket

lib/config-schema.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,19 @@ const schema = {
210210
additionalProperties: false,
211211
},
212212
service: { $ref: '#/definitions/serviceName' },
213+
state: {
214+
anyOf: [
215+
{
216+
type: 'object',
217+
properties: {
218+
resolver: { type: 'string' },
219+
},
220+
additionalProperties: false,
221+
required: ['resolver'],
222+
},
223+
{ type: 'string' },
224+
],
225+
},
213226
useDotenv: { const: true },
214227
variablesResolutionMode: { type: 'string', enum: ['20210219', '20210326'] },
215228
},

0 commit comments

Comments
 (0)