Skip to content

Commit

Permalink
chore(stepfunctions): add snippet for Map state (#6761)
Browse files Browse the repository at this point in the history
* docs(stepfunctions): Add snippet for Map state

Closes #5736

* address PR feedback

* address PR feedback

* add link to Step Functions documentation

* add backticks to map and parallel in readme

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
shivlaks and mergify[bot] committed Mar 24, 2020
1 parent b3abc68 commit 1e92564
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
33 changes: 25 additions & 8 deletions packages/@aws-cdk/aws-stepfunctions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,14 @@ This library comes with a set of classes that model the [Amazon States
Language](https://states-language.net/spec.html). The following State classes
are supported:

* `Task`
* `Pass`
* `Wait`
* `Choice`
* `Parallel`
* `Succeed`
* `Fail`
* [`Task`](#task)
* [`Pass`](#pass)
* [`Wait`](#wait)
* [`Choice`](#choice)
* [`Parallel`](#parallel)
* [`Succeed`](#succeed)
* [`Fail`](#fail)
* [`Map`](#map)

An arbitrary JSON object (specified at execution start) is passed from state to
state and transformed during the execution of the workflow. For more
Expand Down Expand Up @@ -461,7 +462,7 @@ wait.next(startTheWork);

### Choice

A `Choice` state can take a differen path through the workflow based on the
A `Choice` state can take a different path through the workflow based on the
values in the execution's JSON state:

```ts
Expand Down Expand Up @@ -538,6 +539,22 @@ const success = new stepfunctions.Fail(this, 'Fail', {
});
```

### Map

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.

```ts
const map = new stepfunctions.Map(this, 'Map State', {
maxConcurrency: 1,
itemsPath: stepfunctions.Data.stringAt('$.inputForMap')
});
map.iterator(new stepfunctions.Pass(this, 'Pass State'));
```

## Task Chaining

To make defining work flows as convenient (and readable in a top-to-bottom way)
Expand Down
8 changes: 6 additions & 2 deletions packages/@aws-cdk/aws-stepfunctions/lib/states/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,13 @@ export const isPositiveInteger = (value: number) => {
/**
* Define a Map state in the state machine
*
* A Map state can be used to dynamically process elements of an array through sub state machines
* 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.
*
* The Result of a Map state is the transformed array after processing through the iterator state machines.
* 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.
*
* @see https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-map-state.html
*/
export class Map extends State implements INextable {
public readonly endStates: INextable[];
Expand Down

0 comments on commit 1e92564

Please sign in to comment.