# DistributedMap

Define a Distributed Mode 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.

A `Map` state in `Distributed` mode will execute a child workflow for each iteration of the Map state.
This serves to increase concurrency and allows for larger workloads to be run in a single state machine.

Extends: Construct › State › MapBase › DistributedMap
Implements: IChainable, INextable, IConstruct, IDependable

- Source: [`aws-stepfunctions/lib/states/distributed-map.ts`](https://github.com/aws/aws-cdk/blob/v2.274.0/packages/aws-cdk-lib/aws-stepfunctions/lib/states/distributed-map.ts#L139)
- Type last changed: v2.178.0 · 6 Feb 2025

## Example

```ts
/**
 * JSON state input:
 *  {
 *    "bucketName": "my-bucket"
 *  }
 */
const distributedMap = new sfn.DistributedMap(this, 'DistributedMap', {
  resultWriterV2: new sfn.ResultWriterV2({
    bucketNamePath: sfn.JsonPath.stringAt('$.bucketName'),
  }),
});
distributedMap.itemProcessor(new sfn.Pass(this, 'Pass'));
```

## Initializer

```ts
new DistributedMap(scope: Construct, id: string, props?: DistributedMapProps)
```

## Construct Props

- `assign`: { [key: string]: any } = Not assign variables — Workflow variables to store in this step.

  Using workflow variables, you can store data in a step and retrieve that data in future steps.

- `comment`: string = No comment — A comment describing this state.

- `inputPath`: string = $ — 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 {}.

- `itemBatcher`: [ItemBatcher](/cdk/api/v2/docs/aws-cdk-lib.aws_stepfunctions.ItemBatcher.html) = No itemBatcher — Specifies to process a group of items in a single child workflow execution.

- `itemReader`: [IItemReader](/cdk/api/v2/docs/aws-cdk-lib.aws_stepfunctions.IItemReader.html) = No itemReader — ItemReader.

  Configuration for where to read items dataset in S3 to iterate

- `items`: [ProvideItems](/cdk/api/v2/docs/aws-cdk-lib.aws_stepfunctions.ProvideItems.html) = The state input as is. — The array that the Map state will iterate over.

- `itemSelector`: { [key: string]: any } = $ — The JSON that you want to override your default iteration input (mutually exclusive with `parameters` and `jsonataItemSelector`).

- `itemsPath`: string = $ — JSONPath expression to select the array to iterate over.

- `jsonataItemSelector`: string = $ — Jsonata expression that evaluates to a JSON array to override your default iteration input (mutually exclusive with `parameters` and `itemSelector`).

  Example value: `{% {\"foo\": \"foo\", \"input\": $states.input} %}`

- `jsonataMaxConcurrency`: string = full concurrency — JSONata expression for MaxConcurrency.

  A JSONata expression that evaluates to an integer, specifying the maximum
  concurrency dynamically. Mutually exclusive with `maxConcurrency` and
  `maxConcurrencyPath`.

  Example value: `{% $states.input.maxConcurrency %}`

- `label`: string = No label — Label.

  Unique name for the Distributed Map state added to each Map Run

- `mapExecutionType`: [StateMachineType](/cdk/api/v2/docs/aws-cdk-lib.aws_stepfunctions.StateMachineType.html) = StateMachineType.STANDARD — MapExecutionType.

  The execution type of the distributed map state

  This property overwrites ProcessorConfig.executionType

- `maxConcurrency`: number = full concurrency — MaxConcurrency.

  An upper bound on the number of iterations you want running at once.

- `maxConcurrencyPath`: string = full concurrency — MaxConcurrencyPath.

  A JsonPath that specifies the maximum concurrency dynamically from the state input.

- `outputPath`: string = $ — 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 {}.

- `outputs`: any = $states.result or $states.errorOutput — Used to specify and transform output from the state.

  When specified, the value overrides the state output default.
  The output field accepts any JSON value (object, array, string, number, boolean, null).
  Any string value, including those inside objects or arrays,
  will be evaluated as JSONata if surrounded by {% %} characters.
  Output also accepts a JSONata expression directly.

  **Default:** $states.result or $states.errorOutput

- `queryLanguage`: [QueryLanguage](/cdk/api/v2/docs/aws-cdk-lib.aws_stepfunctions.QueryLanguage.html) = JSONPath — The name of the query language used by the state.

  If the state does not contain a `queryLanguage` field,
  then it will use the query language specified in the top-level `queryLanguage` field.

- `resultPath`: string = $ — 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`: { [key: string]: any } = 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.

- `resultWriter`: [ResultWriter](/cdk/api/v2/docs/aws-cdk-lib.aws_stepfunctions.ResultWriter.html) = No resultWriter — Use {@link resultWriterV2 }

- `resultWriterV2`: [ResultWriterV2](/cdk/api/v2/docs/aws-cdk-lib.aws_stepfunctions.ResultWriterV2.html) = No resultWriterV2 — Configuration for S3 location in which to save Map Run results Enable "@aws-cdk/aws-stepfunctions:useDistributedMapResultWriterV2" feature in the context to use resultWriterV2 Example: stack.node.setContext("@aws-cdk/aws-stepfunctions:useDistributedMapResultWriterV2", true);

- `stateName`: string = The construct ID will be used as state name — Optional name for this state.

  **Default:** The construct ID will be used as state name

- `toleratedFailureCount`: number = No toleratedFailureCount — ToleratedFailureCount.

  Number of failed items to tolerate in a Map Run, as static number

- `toleratedFailureCountPath`: string = No toleratedFailureCountPath — ToleratedFailureCountPath.

  Number of failed items to tolerate in a Map Run, as JsonPath

- `toleratedFailurePercentage`: number = No toleratedFailurePercentage — ToleratedFailurePercentage.

  Percentage of failed items to tolerate in a Map Run, as static number

- `toleratedFailurePercentagePath`: string = No toleratedFailurePercentagePath — ToleratedFailurePercentagePath.

  Percentage of failed items to tolerate in a Map Run, as JsonPath

  **Default:** No toleratedFailurePercentagePath

## Properties

- `endStates`: [INextable](/cdk/api/v2/docs/aws-cdk-lib.aws_stepfunctions.INextable.html)[] (required) — Continuable states of this Chainable.

- `id`: string (required) — Descriptive identifier for this chainable.

- `node`: [Node](/cdk/api/v2/docs/constructs.Node.html) (required) — The tree node.

- `startState`: [State](/cdk/api/v2/docs/aws-cdk-lib.aws_stepfunctions.State.html) (required) — First state of this Chainable.

- `stateId`: string (required) — Tokenized string that evaluates to the state's ID.

## Methods

- `addCatch(handler: IChainable, props?: CatchProps): DistributedMap // chainable` — 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: string): void` — Add a prefix to the stateId of this state.

- `addRetry(props?: RetryProps): DistributedMap // chainable` — Add retry configuration for this state.

  This controls if and how the execution will be retried if a particular
  error occurs.

- `bindToGraph(graph: StateGraph): void` — Register this state as part of the given graph.

  Don't call this. It will be called automatically when you work
  with states normally.

- `filterNextables(states: State[]): INextable[]` (static) — Return only the states that allow chaining from an array of states.

- `findReachableEndStates(start: State, options?: FindStateOptions): State[]` (static) — Find the set of end states states reachable through transitions from the given start state.

- `findReachableStates(start: State, options?: FindStateOptions): State[]` (static) — Find the set of states reachable through transitions from the given start state.

  This does not retrieve states from within sub-graphs, such as states within a Parallel state's branch.

- `isConstruct(x: any): boolean` (static) — Checks if `x` is a construct.

  Use this method instead of `instanceof` to properly detect `Construct`
  instances, even when the construct library is symlinked.

  Explanation: in JavaScript, multiple copies of the `constructs` library on
  disk are seen as independent, completely different libraries. As a
  consequence, the class `Construct` in each copy of the `constructs` library
  is seen as a different class, and an instance of one class will not test as
  `instanceof` the other class. `npm install` will not create installations
  like this, but users may manually symlink construct libraries together or
  use a monorepo tool: in those cases, multiple copies of the `constructs`
  library can be accidentally installed, and `instanceof` will behave
  unpredictably. It is safest to avoid using `instanceof`, and using
  this type-testing method instead.

  **Parameters**

  - `x` — Any object.

  **Returns:** true if `x` is an object created from a class which extends `Construct`.

- `isDistributedMap(x: any): boolean` (static) — Return whether the given object is a DistributedMap.

- `itemProcessor(processor: IChainable, config?: ProcessorConfig): DistributedMap // chainable` — Define item processor in a Distributed Map.

  A Distributed Map must have a non-empty item processor

- `jsonata(scope: Construct, id: string, props?: DistributedMapJsonataProps): DistributedMap // chainable` (static) — Define a Distributed Mode Map state using JSONata 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.

  A `Map` state in `Distributed` mode will execute a child workflow for each iteration of the Map state.
  This serves to increase concurrency and allows for larger workloads to be run in a single state machine.

- `jsonPath(scope: Construct, id: string, props?: DistributedMapJsonPathProps): DistributedMap // chainable` (static) — Define a Distributed Mode Map state using JSONPath 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.

  A `Map` state in `Distributed` mode will execute a child workflow for each iteration of the Map state.
  This serves to increase concurrency and allows for larger workloads to be run in a single state machine.

- `next(next: IChainable): Chain` — Continue normal execution with the given state.

- `prefixStates(root: IConstruct, prefix: string): void` (static) — Add a prefix to the stateId of all States found in a construct tree.

- `toStateJson(stateMachineQueryLanguage?: QueryLanguage): json` — Return the Amazon States Language object for this state.

- `toString(): string` — Returns a string representation of this construct.

- `with(...mixins: IMixin[]): IConstruct` — Applies one or more mixins to this construct.

  Mixins are applied in order. The list of constructs is captured at the
  start of the call, so constructs added by a mixin will not be visited.
  Use multiple `with()` calls if subsequent mixins should apply to added
  constructs.

  **Parameters**

  - `mixins` — The mixins to apply.

  **Returns:** This construct for chaining
