class Map (construct)
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.StepFunctions.Map |
Go | github.com/aws/aws-cdk-go/awscdk/v2/awsstepfunctions#Map |
Java | software.amazon.awscdk.services.stepfunctions.Map |
Python | aws_cdk.aws_stepfunctions.Map |
TypeScript (source) | aws-cdk-lib » aws_stepfunctions » Map |
Implements
IConstruct
, IDependable
, IChainable
, INextable
Define a Map state in the state machine.
A Map
state can be used to run a set of steps for each element of an input array.
A Map state will execute the same steps for multiple entries of an array in the state input.
While the Parallel state executes multiple branches of steps using the same input, a Map state will execute the same steps for multiple entries of an array in the state input.
Example
const map = new sfn.Map(this, 'Map State', {
maxConcurrency: 1,
itemsPath: sfn.JsonPath.stringAt('$.inputForMap'),
itemSelector: {
item: sfn.JsonPath.stringAt('$$.Map.Item.Value'),
},
resultPath: '$.mapOutput',
});
// The Map iterator can contain a IChainable, which can be an individual or multiple steps chained together.
// Below example is with a Choice and Pass step
const choice = new sfn.Choice(this, 'Choice');
const condition1 = sfn.Condition.stringEquals('$.item.status', 'SUCCESS');
const step1 = new sfn.Pass(this, 'Step1');
const step2 = new sfn.Pass(this, 'Step2');
const finish = new sfn.Pass(this, 'Finish');
const definition = choice
.when(condition1, step1)
.otherwise(step2)
.afterwards()
.next(finish);
map.itemProcessor(definition);
Initializer
new Map(scope: Construct, id: string, props?: MapProps)
Parameters
Construct Props
Name | Type | Description |
---|---|---|
comment? | string | An optional description for this state. |
input | string | JSONPath expression to select part of the state to be the input to this state. |
item | { [string]: any } | The JSON that you want to override your default iteration input (mutually exclusive with parameters ). |
items | string | JSONPath expression to select the array to iterate over. |
max | number | MaxConcurrency. |
max | string | MaxConcurrencyPath. |
output | string | JSONPath expression to select part of the state to be the output to this state. |
parameters? | { [string]: any } | The JSON that you want to override your default iteration input (mutually exclusive with itemSelector ). |
result | string | JSONPath expression to indicate where to inject the state's output. |
result | { [string]: any } | The JSON that will replace the state's raw result and become the effective result before ResultPath is applied. |
state | string | Optional name for this state. |
comment?
Type:
string
(optional, default: No comment)
An optional description for this state.
inputPath?
Type:
string
(optional, default: $)
JSONPath expression to select part of the state to be the input to this state.
May also be the special value JsonPath.DISCARD, which will cause the effective input to be the empty object {}.
itemSelector?
Type:
{ [string]: any }
(optional, default: $)
The JSON that you want to override your default iteration input (mutually exclusive with parameters
).
itemsPath?
Type:
string
(optional, default: $)
JSONPath expression to select the array to iterate over.
maxConcurrency?
Type:
number
(optional, default: full concurrency)
MaxConcurrency.
An upper bound on the number of iterations you want running at once.
maxConcurrencyPath?
Type:
string
(optional, default: full concurrency)
MaxConcurrencyPath.
A JsonPath that specifies the maximum concurrency dynamically from the state input.
outputPath?
Type:
string
(optional, default: $)
JSONPath expression to select part of the state to be the output to this state.
May also be the special value JsonPath.DISCARD, which will cause the effective output to be the empty object {}.
parameters?
⚠️ Deprecated: Step Functions has deprecated the parameters
field in favor of
the new itemSelector
field
Type:
{ [string]: any }
(optional, default: $)
The JSON that you want to override your default iteration input (mutually exclusive with itemSelector
).
resultPath?
Type:
string
(optional, default: $)
JSONPath expression to indicate where to inject the state's output.
May also be the special value JsonPath.DISCARD, which will cause the state's input to become its output.
resultSelector?
Type:
{ [string]: any }
(optional, default: None)
The JSON that will replace the state's raw result and become the effective result before ResultPath is applied.
You can use ResultSelector to create a payload with values that are static or selected from the state's raw result.
stateName?
Type:
string
(optional, default: The construct ID will be used as state name)
Optional name for this state.
Properties
Name | Type | Description |
---|---|---|
end | INextable [] | Continuable states of this Chainable. |
id | string | Descriptive identifier for this chainable. |
node | Node | The tree node. |
start | State | First state of this Chainable. |
state | string | Tokenized string that evaluates to the state's ID. |
endStates
Type:
INextable
[]
Continuable states of this Chainable.
id
Type:
string
Descriptive identifier for this chainable.
node
Type:
Node
The tree node.
startState
Type:
State
First state of this Chainable.
stateId
Type:
string
Tokenized string that evaluates to the state's ID.
Methods
Name | Description |
---|---|
add | Add a recovery handler for this state. |
add | Add a prefix to the stateId of this state. |
add | Add retry configuration for this state. |
bind | Register this state as part of the given graph. |
item | Define item processor in Map. |
iterator(iterator) | Define iterator state machine in Map. |
next(next) | Continue normal execution with the given state. |
to | Return the Amazon States Language object for this state. |
to | Returns a string representation of this construct. |
protected validate | Validate this state. |
addCatch(handler, props?)
public addCatch(handler: IChainable, props?: CatchProps): Map
Parameters
- handler
IChainable
- props
Catch
Props
Returns
Add a recovery handler for this state.
When a particular error occurs, execution will continue at the error handler instead of failing the state machine execution.
addPrefix(x)
public addPrefix(x: string): void
Parameters
- x
string
Add a prefix to the stateId of this state.
addRetry(props?)
public addRetry(props?: RetryProps): Map
Parameters
- props
Retry
Props
Returns
Add retry configuration for this state.
This controls if and how the execution will be retried if a particular error occurs.
bindToGraph(graph)
public bindToGraph(graph: StateGraph): void
Parameters
- graph
State
Graph
Register this state as part of the given graph.
Don't call this. It will be called automatically when you work with states normally.
itemProcessor(processor, config?)
public itemProcessor(processor: IChainable, config?: ProcessorConfig): Map
Parameters
- processor
IChainable
- config
Processor
Config
Returns
Define item processor in Map.
A Map must either have a non-empty iterator or a non-empty item processor (mutually exclusive with iterator
).
iterator(iterator)
public iterator(iterator: IChainable): Map
⚠️ Deprecated: - use itemProcessor
instead.
Parameters
- iterator
IChainable
Returns
Define iterator state machine in Map.
A Map must either have a non-empty iterator or a non-empty item processor (mutually exclusive with itemProcessor
).
next(next)
public next(next: IChainable): Chain
Parameters
- next
IChainable
Returns
Continue normal execution with the given state.
toStateJson()
public toStateJson(): json
Returns
json
Return the Amazon States Language object for this state.
toString()
public toString(): string
Returns
string
Returns a string representation of this construct.
protected validateState()
protected validateState(): string[]
Returns
string[]
Validate this state.