Skip to content
23K
Console

Parallel

The Parallel state is internally used by the StepFunctions component to add a Parallel workflow state to a state machine.

You’ll find this component returned by the parallel method of the StepFunctions component.


Constructor

new Parallel(args)

Parameters

ParallelArgs

arguments?

Type Input<Record<string, Input<any>>>

The arguments to be passed to the APIs of the connected resources. Values can include outputs from other resources and JSONata expressions.

{
arguments: {
product: "{% $states.input.order.product %}",
url: api.url,
count: 32
}
}

assign?

Type Record<string, any>

Store variables that can be accessed by any state later in the workflow, instead of passing it through each state.

This takes a set of key/value pairs. Where the key is the name of the variable that can be accessed by any subsequent state.

The value can be any JSON value; object, array, string, number, boolean, null.

{
assign: {
productName: "product1",
count: 42,
available: true
}
}

Or, you can pass in a JSONata expression.

{
assign: {
product: "{% $states.input.order.product %}",
currentPrice: "{% $states.result.Payload.current_price %}"
}
}

Learn more about passing data between states with variables.

name

Type string

The name of the state. This needs to be unique within the state machine.

output?

Type Input<Record<string, any> | {% ${string} %}>

Transform the output of the state. When specified, the value overrides the default output from the state.

This takes any JSON value; object, array, string, number, boolean, null.

{
output: {
charged: true
}
}

Or, you can pass in a JSONata expression.

{
output: {
product: "{% $states.input.product %}"
}
}

Learn more about transforming data with JSONata.

Methods

branch

branch(branch)

Parameters

  • branch State

    The state to add as a branch.

Returns Parallel

Add a branch state to the Parallel state. Each branch runs concurrently.

sst.config.ts
const parallel = sst.aws.StepFunctions.parallel({ name: "Parallel" });
parallel.branch(processorA);
parallel.branch(processorB);

catch

catch(state, args?)

Parameters

  • state State

    The state to transition to on error.
  • args? CatchArgs

    Properties to customize error handling.

Returns Parallel

Add a catch behavior to the Parallel state. So if the state fails with any of the specified errors, it’ll continue execution to the given state.

This defaults to.

sst.config.ts
sst.aws.StepFunctions.parallel({
// ...
})
.catch({
errors: ["States.ALL"]
});

next

next(state)

Parameters

  • state State

    The state to transition to.

Returns State

Add a next state to the Parallel state. If all branches complete successfully, this’ll continue execution to the given state.

sst.config.ts
sst.aws.StepFunctions.parallel({
// ...
})
.next(state);

retry

retry(args?)

Parameters

  • args? RetryArgs

    Properties to define the retry behavior.

Returns Parallel

Add a retry behavior to the Parallel state. If the state fails with any of the specified errors, retry execution using the specified parameters.

This defaults to.

sst.config.ts
sst.aws.StepFunctions.parallel({
// ...
})
.retry({
errors: ["States.ALL"],
interval: "1 second",
maxAttempts: 3,
backoffRate: 2
});