Skip to content

Commit

Permalink
fix: add state to the config schema (#12909)
Browse files Browse the repository at this point in the history
  • Loading branch information
czubocha authored Nov 15, 2024
1 parent 5fea01a commit ad16b0a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
27 changes: 16 additions & 11 deletions docs/guides/state.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<!--
title: 'Serverless Framework State'
description: 'Learn how to manage state in Serverless Framework Compose.'
description: 'Learn how to manage state in Serverless Framework'
short_title: Serverless Framework State
keywords:
[
'Serverless Framework',
'serverless-compose',
'state management',
'S3 state',
'service state',
Expand All @@ -20,28 +19,33 @@ keywords:

# Serverless Framework State

Serverless Framework Compose allows for the orchestration and deployment of multiple services.
Serverless Framework allows for the orchestration and deployment of multiple services.
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.
This guide covers how to set up and manage state using AWS S3 and AWS SSM.

**Note:** Starting from Serverless Framework v4.4.8, the state is saved for all services, not just when using Compose.
This ensures seamless transitions between Compose and non-Compose deployments without losing state information.

## State Management Overview

State management in Serverless Framework Compose is crucial for:
State management in Serverless Framework is crucial for:

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

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.
Serverless Framework uses AWS S3 to store the state of services and AWS SSM (Systems Manager) to track the location of the state storage.

## Zero-Configuration Setup

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.
The easiest way to manage state in Serverless Framework is through its default, zero-configuration setup.
When you don’t specify any state configuration, Serverless Framework automatically handles everything for you.
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.

### How It Works

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.
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:
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.
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:

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

### Example
### Using State with Serverless Framework Compose

Assume you have the following serverless-compose.yml with two services:
Assume you have the following configuration with two services:

```yaml
services:
Expand Down Expand Up @@ -98,7 +102,8 @@ making it easy to manage and deploy services with complex interdependencies.
## Custom State Configuration

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

### Using a Custom S3 Bucket
Expand Down
13 changes: 13 additions & 0 deletions lib/config-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,19 @@ const schema = {
additionalProperties: false,
},
service: { $ref: '#/definitions/serviceName' },
state: {
anyOf: [
{
type: 'object',
properties: {
resolver: { type: 'string' },
},
additionalProperties: false,
required: ['resolver'],
},
{ type: 'string' },
],
},
useDotenv: { const: true },
variablesResolutionMode: { type: 'string', enum: ['20210219', '20210326'] },
},
Expand Down

0 comments on commit ad16b0a

Please sign in to comment.