# Map

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.

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

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

## Example

```ts
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',
});

map.itemProcessor(new sfn.Pass(this, 'Pass State'), {
  mode: sfn.ProcessorMode.DISTRIBUTED,
  executionType: sfn.ProcessorType.STANDARD,
});
```

## Initializer

```ts
new Map(scope: Construct, id: string, props?: MapProps)
```

## Construct Props

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

  **Default:** Not assign variables

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

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

  **Default:** No comment

- `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 {}.

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

  **Default:** The state input as is.

- `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 — JSONata expression for MaxConcurrency.

  **Default:** full concurrency

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

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

- `maxConcurrency`: number — MaxConcurrency.

  **Default:** full concurrency

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

- `maxConcurrencyPath`: string — MaxConcurrencyPath.

  **Default:** full concurrency

  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 — Used to specify and transform output from the state.

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

  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.

- `parameters`: { [key: string]: any } = $ — Step Functions has deprecated the `parameters` field in favor of the new `itemSelector` field

- `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.

- `stateName`: string — Optional name for this state.

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

## 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): Map // 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): Map // 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`.

- `itemProcessor(processor: IChainable, config?: ProcessorConfig): Map // chainable` — 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: IChainable): Map // chainable` — - use `itemProcessor` instead.

  A Map must either have a non-empty iterator or a non-empty item processor (mutually exclusive  with `itemProcessor`).

- `jsonata(scope: Construct, id: string, props?: MapJsonataProps): Map // chainable` (static) — Define a 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.

- `jsonPath(scope: Construct, id: string, props?: MapJsonPathProps): Map // chainable` (static) — Define a 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.

- `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(queryLanguage?: 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
