I have started doing this in my own project. See an example for my specific use case below
I'm raising this issue to see where/how/if we can develop a complete definition collectively.
// serverless.ts
import { Serverless } from "serverless/aws";
import { contentfulEnvironmentVariables } from "./src/config/contenful";
type Definition = {
Comment?: string;
StartAt: string;
States: {
[state: string]: {
Catch?: Catcher[];
Type: "Map" | "Task" | "Choice" | "Pass";
End?: boolean;
Next?: string;
ItemsPath?: string;
ResultPath?: string;
Resource?: string | { "Fn::GetAtt": string[] };
Iterator?: Definition;
};
};
};
type Catcher = {
ErrorEquals: ErrorName[];
Next: string;
ResultPath?: string;
};
type ErrorName =
| "States.ALL"
| "States.DataLimitExceeded"
| "States.Runtime"
| "States.Timeout"
| "States.TaskFailed"
| "States.Permissions"
| string;
interface ServerlessWithStepFunctions extends Serverless {
stepFunctions: {
stateMachines: {
[stateMachine: string]: {
name: string;
definition: Definition;
};
};
activities?: string[];
validate?: boolean;
};
}
// example config (in a Typescript Serverless project this can be used in place of serverless.yml)
const serverlessConfiguration: ServerlessWithStepFunctions = {
service: {
name: "xxx",
},
frameworkVersion: ">=1.72.0",
custom: {
webpack: {
webpackConfig: "./webpack.config.js",
includeModules: true,
},
},
plugins: ["serverless-step-functions", "serverless-webpack"],
provider: {
name: "aws",
region: "eu-west-1",
runtime: "nodejs12.x",
timeout: 60,
apiGateway: {
minimumCompressionSize: 1024,
},
environment: {
AWS_NODEJS_CONNECTION_REUSE_ENABLED: "1",
},
},
functions: {
createImageInContentful: {
handler: "src/titles/createImage.handler",
description: "Create an image asset in Contentful",
environment: { ...contentfulEnvironmentVariables },
},
publishImageInContentful: {
handler: "src/titles/publishImage.handler",
description: "Publish an image asset in Contentful",
environment: { ...contentfulEnvironmentVariables },
},
},
stepFunctions: {
stateMachines: {
migrateAllTitlesMainImage: {
name: "MigrateAllTitlesMainImage",
definition: {
Comment: "Migrate images from titles from Airtable into Contentful",
StartAt: "MigrateAll",
States: {
MigrateAll: {
Type: "Map",
End: true,
ItemsPath: "$.titles",
Iterator: {
StartAt: "CreateContentfulAsset",
States: {
CreateContentfulAsset: {
Type: "Task",
Next: "PublishContentfulAsset",
Resource: {
"Fn::GetAtt": ["createImageInContentful", "Arn"],
},
Catch: [
{
ErrorEquals: ["VersionMismatch"],
ResultPath: "$.CreateContentfulAssetError",
Next: "AssetAlreadyCreated",
},
],
ResultPath: "$.CreateContentfulAssetResult",
},
AssetAlreadyCreated: {
Type: "Pass",
Next: "PublishContentfulAsset",
},
PublishContentfulAsset: {
Type: "Task",
End: true,
Resource: {
"Fn::GetAtt": ["publishImageInContentful", "Arn"],
},
},
},
},
},
},
},
},
},
activities: ["content-migration-titles-images"],
validate: true,
},
};
module.exports = serverlessConfiguration;
Serverless Version: 1.78.1
Plugin Version: 2.22.1
Let's have a Typescript types for serverless-step-functions
Why
serverless-step-functionsbecausestepFunctionsis not expected by Serverless defintionstepFunctionsWhat
Notes
I have started doing this in my own project. See an example for my specific use case below
I'm raising this issue to see where/how/if we can develop a complete definition collectively.