Skip to content
23K
Console

StepFunctions

The StepFunctions component lets you add state machines to your app using AWS Step Functions.

You define your state machine using a collection of states. Where each state needs a unique name. It uses JSONata for transforming data between states.

Minimal example

The state machine definition is compiled into JSON and passed to AWS.

sst.config.ts
const foo = sst.aws.StepFunctions.pass({ name: "Foo" });
const bar = sst.aws.StepFunctions.succeed({ name: "Bar" });
const definition = foo.next(bar);
new sst.aws.StepFunctions("MyStateMachine", {
definition
});

Invoking a Lambda function

Create a function and invoke it from a state machine.

sst.config.ts
const myFunction = new sst.aws.Function("MyFunction", {
handler: "src/index.handler"
});
const invoke = sst.aws.StepFunctions.lambdaInvoke({
name: "InvokeMyFunction",
function: myFunction
});
const done = sst.aws.StepFunctions.succeed({ name: "Done" });
new sst.aws.StepFunctions("MyStateMachine", {
definition: invoke.next(done)
});

Use the express workflow

sst.config.ts
const foo = sst.aws.StepFunctions.pass({ name: "Foo" });
const bar = sst.aws.StepFunctions.succeed({ name: "Bar" });
new sst.aws.StepFunctions("MyStateMachine", {
type: "express",
definition: foo.next(bar)
});

Constructor

new StepFunctions(name, args, opts?)

Parameters

StepFunctionsArgs

definition

Type State

The definition of the state machine. It takes a chain of State objects.

sst.config.ts
const foo = sst.aws.StepFunctions.pass({ name: "Foo" });
const bar = sst.aws.StepFunctions.succeed({ name: "Bar" });
new sst.aws.StepFunctions("MyStateMachine", {
definition: foo.next(bar)
});

logging?

Type Input<false | Object>

Default {retention: “1 month”, level: “error”, includeData: false}

Configure the execution logs in CloudWatch. Or pass in false to disable writing logs.

{
logging: false
}

logging.includeData?

Type Input<boolean>

Default false

Specify whether execution data is included in the logs.

{
logging: {
includeData: true
}
}

logging.level?

Type Input<all | error | fatal>

Default “error”

Specify the type of execution events that are logged. Read more about the Step Functions log level.

{
logging: {
level: "all"
}
}

logging.retention?

Type Input<1 day | 3 days | 5 days | 1 week | 2 weeks | 1 month | 2 months | 3 months | 4 months | 5 months | 6 months | 1 year | 13 months | 18 months | 2 years | 3 years | 5 years | 6 years | 7 years | 8 years | 9 years | 10 years | forever>

Default 1 month

The duration the logs are kept in CloudWatch.

{
logging: {
retention: "forever"
}
}

transform?

Type Object

Transform how this component creates its underlying resources.

transform.logGroup?

Type LogGroupArgs | (args: LogGroupArgs, opts: ComponentResourceOptions, name: string) => void

Transform the Step Functions LogGroup resource.

transform.stateMachine?

Type StateMachineArgs | (args: StateMachineArgs, opts: ComponentResourceOptions, name: string) => void

Transform the Step Functions StateMachine resource.

type?

Type Input<standard | express>

Default “standard”

The type of state machine workflow to create.

The standard workflow is the default and is meant for long running workflows. The express workflow is meant for workflows shorter than 5 minutes.

This is because the express workflow is run in a single Lambda function. As a result, it’s faster and cheaper to run. So if your workflow are short, the express workflow is recommended.

{
type: "express"
}

Properties

arn

Type Output<string>

The State Machine ARN.

nodes

Type Object

The underlying resources this component creates.

nodes.stateMachine

Type StateMachine

The Step Function State Machine resource.

SDK

Use the SDK in your runtime to interact with your infrastructure.


This is accessible through the Resource object in the SDK.

  • arn string

    The State Machine ARN.

Methods

static choice

StepFunctions.choice(args)

Parameters

Returns Choice

A Choice state is used to conditionally continue to different states based on the matched condition.

sst.config.ts
const processPayment = sst.aws.StepFunctions.choice({ name: "ProcessPayment" });
const makePayment = sst.aws.StepFunctions.lambdaInvoke({ name: "MakePayment" });
const sendReceipt = sst.aws.StepFunctions.lambdaInvoke({ name: "SendReceipt" });
const failure = sst.aws.StepFunctions.fail({ name: "Failure" });
processPayment.when("{% $states.input.status === 'unpaid' %}", makePayment);
processPayment.when("{% $states.input.status === 'paid' %}", sendReceipt);
processPayment.otherwise(failure);

static fail

StepFunctions.fail(args)

Parameters

Returns Fail

A Fail state is used to fail the execution of a state machine.

sst.config.ts
sst.aws.StepFunctions.fail({ name: "Failure" });

static map

StepFunctions.map(args)

Parameters

Returns Map

A Map state is used to iterate over a list of items and execute a task for each item.

sst.config.ts
const processor = sst.aws.StepFunctions.lambdaInvoke({
name: "Processor",
function: "src/processor.handler"
});
sst.aws.StepFunctions.map({
processor,
name: "Map",
items: "{% $states.input.items %}"
});

static parallel

StepFunctions.parallel(args)

Parameters

Returns Parallel

A Parallel state is used to execute multiple branches of a state in parallel.

sst.config.ts
const processorA = sst.aws.StepFunctions.lambdaInvoke({
name: "ProcessorA",
function: "src/processorA.handler"
});
const processorB = sst.aws.StepFunctions.lambdaInvoke({
name: "ProcessorB",
function: "src/processorB.handler"
});
const parallel = sst.aws.StepFunctions.parallel({ name: "Parallel" });
parallel.branch(processorA);
parallel.branch(processorB);

static pass

StepFunctions.pass(args)

Parameters

Returns Pass

A Pass state is used to pass the input to the next state. It’s useful for transforming the input before passing it along.

sst.config.ts
sst.aws.StepFunctions.pass({
name: "Pass",
output: "{% $states.input.message %}"
});

static succeed

StepFunctions.succeed(args)

Parameters

Returns Succeed

A Succeed state is used to indicate that the execution of a state machine has succeeded.

sst.config.ts
sst.aws.StepFunctions.succeed({ name: "Succeed" });

static task

StepFunctions.task(args)

Parameters

Returns Task

A Task state can be used to make calls to AWS resources. We created a few convenience methods for common tasks like:

  • sst.aws.StepFunctions.lambdaInvoke to invoke a Lambda function.
  • sst.aws.StepFunctions.ecsRunTask to run an ECS task.
  • sst.aws.StepFunctions.eventBridgePutEvents to send custom events to EventBridge.

For everything else, you can use the Task state.

For example, to start an AWS CodeBuild build.

sst.config.ts
sst.aws.StepFunctions.task({
name: "Task",
resource: "arn:aws:states:::codebuild:startBuild",
arguments: {
projectName: "my-codebuild-project"
},
permissions: [
{
actions: ["codebuild:StartBuild"],
resources: ["*"]
}
]
});

static wait

StepFunctions.wait(args)

Parameters

Returns Wait

A Wait state is used to wait for a specific amount of time before continuing to the next state.

For example, wait for 10 seconds before continuing to the next state.

sst.config.ts
sst.aws.StepFunctions.wait({
name: "Wait",
time: 10
});

Alternatively, you can wait until a specific timestamp.

sst.config.ts
sst.aws.StepFunctions.wait({
name: "Wait",
timestamp: "2026-01-01T00:00:00Z"
});

static ecsRunTask

StepFunctions.ecsRunTask(args)

Parameters

Returns Task

Create a Task state that runs an ECS task using the Task component. Learn more.

sst.config.ts
const myCluster = new sst.aws.Cluster("MyCluster");
const myTask = new sst.aws.Task("MyTask", { cluster: myCluster });
sst.aws.StepFunctions.ecsRunTask({
name: "RunTask",
task: myTask
});

static eventBridgePutEvents

StepFunctions.eventBridgePutEvents(args)

Parameters

Returns Task

Create a Task state that sends custom events to one or more EventBridge buses using the Bus component. Learn more.

sst.config.ts
const myBus = new sst.aws.EventBus("MyBus");
sst.aws.StepFunctions.eventBridgePutEvents({
name: "EventBridgePutEvents",
events: [
{
bus: myBus,
source: "my-source"
}
]
});

static lambdaInvoke

StepFunctions.lambdaInvoke(args)

Parameters

Returns Task

Create a Task state that invokes a Lambda function. Learn more.

sst.config.ts
sst.aws.StepFunctions.lambdaInvoke({
name: "LambdaInvoke",
function: "src/index.handler"
});

Customize the function.

sst.config.ts
sst.aws.StepFunctions.lambdaInvoke({
name: "LambdaInvoke",
function: {
handler: "src/index.handler"
timeout: "60 seconds",
}
});

Pass in an existing Function component.

sst.config.ts
const myLambda = new sst.aws.Function("MyLambda", {
handler: "src/index.handler"
});
sst.aws.StepFunctions.lambdaInvoke({
name: "LambdaInvoke",
function: myLambda
});

Or pass in the ARN of an existing Lambda function.

sst.config.ts
sst.aws.StepFunctions.lambdaInvoke({
name: "LambdaInvoke",
function: "arn:aws:lambda:us-east-1:123456789012:function:my-function"
});

static snsPublish

StepFunctions.snsPublish(args)

Parameters

Returns Task

Create a Task state that publishes a message to an SNS topic. Learn more.

sst.config.ts
const myTopic = new sst.aws.SnsTopic("MyTopic");
sst.aws.StepFunctions.snsPublish({
name: "SnsPublish",
topic: myTopic,
message: "Hello, world!"
});

static sqsSendMessage

StepFunctions.sqsSendMessage(args)

Parameters

Returns Task

Create a Task state that sends a message to an SQS queue. Learn more.

sst.config.ts
const myQueue = new sst.aws.Queue("MyQueue");
sst.aws.StepFunctions.sqsSendMessage({
name: "SqsSendMessage",
queue: myQueue,
messageBody: "Hello, world!"
});