Movatterモバイル変換


[0]ホーム

URL:


Using Map state in Inline mode in Step Functions workflows - AWS Step Functions
DocumentationAWS Step FunctionsDeveloper Guide
Key concepts in this topicInline Map state fieldsDeprecated fieldsInline Map state example (JSONPath)Inline Map state example with ItemSelectorInline Map state input and output processing

Using Map state in Inline mode in Step Functions workflows

By default,Map states runs inInline mode. In Inline mode, the Map state accepts only a JSON array as input. It receives this array from a previous step in the workflow. In this mode, each iteration of theMap state runs in the context of the workflow that contains theMap state. Step Functions adds the execution history of these iterations to the parent workflow's execution history.

In this mode, theMap state supports up to 40 concurrent iterations.

AMap state set toInline is known as anInline Map state. Use theMap state in Inline mode if your workflow's execution history won't exceed 25,000 entries, or if you don't require more than 40 concurrent iterations.

For an introduction to using theInline Map state, see the tutorialRepeat actions with Inline Map.

Key concepts in this topic

Inline mode

A limited-concurrency mode of theMap state. In this mode, each iteration of theMap state runs in the context of the workflow that contains theMap state. Step Functions adds the execution history of these iterations to the parent workflow's execution history.Map states run in the Inline mode by default.

This mode accepts only a JSON array as input and supports up to 40 concurrent iterations.

Inline Map state

AMap state set to theInline mode.

Map workflow

The set of steps that theMap state runs for each iteration.

Map state iteration

A repetition of the workflow defined inside of theMap state.

Inline Map state fields

To use theInline Map state in your workflows, specify one or more of these fields. You specify these fields in addition to thecommon state fields.

Type (Required)

Sets the type of state, such asMap.

ItemProcessor
(Required)

Contains the following JSON objects that specify theMap state processing mode and definition.

The definition contains the set of steps to repeat for processing each array item.

  • ProcessorConfig – An optional JSON object that specifies the processing mode for theMap state. This object contains theMode sub-field. This field defaults toINLINE, which uses theMap state in Inline mode.

    In this mode, the failure of any iteration causes theMap state to fail. All iterations stop when theMap state fails.

Items (Optional, JSONata only)

A JSON array or a JSONata expression that must evaluate to an array.

ItemsPath (Optional, JSONPath only)

Specifies areference path using theJsonPath syntax. This path selects the JSON node that contains the array of items inside the state input. For more information, seeItemsPath (Map, JSONPath only).

ItemSelector
(Optional)

Overrides the values of the input array items before they're passed on to eachMap state iteration.

In this field, you specify a valid JSON that contains a collection of key-value pairs. These pairs can contain any of the following:

  • Static values you define in your state machine definition.

  • Values selected from the state input using apath.

  • Values accessed from thecontext object.

For more information, seeItemSelector (Map).

TheItemSelector field replaces the now deprecatedParameters field. Although you can continue to includeMap states that use theParameters field, we highly recommend that you replace this field withItemSelector.

MaxConcurrency (Optional)

Specifies an integer value that provides the upper bound on the number ofMap state iterations that can run in parallel. For example, aMaxConcurrency value of 10 limits theMap state to 10 concurrent iterations running at one time.

In JSONata states, you can specify a JSONata expression that evaluates to an integer.

The default value is0, which places no limit on concurrency. Step Functions invokes iterations as concurrently as possible.

AMaxConcurrency value of1 invokes theItemProcessor once for each array element. Items in the array are processed in the order of their appearance in the input. Step Functions doesn't start a new iteration until it completes the previous iteration.

MaxConcurrencyPath (Optional, JSONPath only)

If you want to provide a maximum concurrency value dynamically from the state input using a reference path, useMaxConcurrencyPath. When resolved, the reference path must select a field whose value is a non-negative integer.

ResultPath (Optional, JSONPath only)

Specifies where in the input to store the output of theMap state's iterations. The Map state then filters the input as specified by theOutputPath field, if specified. Then, it uses the filtered input as the state's output. For more information, seeInput and Output Processing.

ResultSelector (Optional, JSONPath only)

Pass a collection of key value pairs, where the values are either static or selected from the result. For more information, seeResultSelector.

Retry (Optional)

An array of objects, called Retriers, that define a retry policy. States use a retry policy when they encounter runtime errors. For more information, seeState machine examples using Retry and Catch.

Catch (Optional)

An array of objects, called Catchers, that define a fallback state. States run a catcher if they encounter runtime errors and either don't have a retry policy, or their retry policy is exhausted. For more information, seeFallback States.

Output (Optional, JSONata only)

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, for example: "Output": "{% jsonata expression %}"

For more information, seeTransforming data with JSONata in Step Functions.

Assign (Optional)

Used to store variables. TheAssign field accepts a JSON object with key/value pairs that define variable names and their assigned values. Any string value, including those inside objects or arrays, will be evaluated as JSONata when surrounded by{% %} characters

For more information, seePassing data between states with variables.

Deprecated fields

Iterator

Specifies a JSON object that defines a set of steps that process each element of the array.

Parameters

Specifies a collection of key-value pairs, where the values can contain any of the following:

  • Static values that you define in your state machine definition.

  • Values selected from the input using apath.

Inline Map state example (JSONPath)

Consider the following input data for aMap state running inInline mode.

{ "ship-date": "2016-03-14T01:59:00Z", "detail":{ "delivery-partner": "UQS", "shipped": [{ "prod": "R31", "dest-code": 9511, "quantity": 1344 },{ "prod": "S39", "dest-code": 9511, "quantity": 40 },{ "prod": "R31", "dest-code": 9833, "quantity": 12 },{ "prod": "R40", "dest-code": 9860, "quantity": 887 },{ "prod": "R40", "dest-code": 9511, "quantity": 1220 } ] }}

Given the previous input, theMap state in the following example invokes an AWS Lambda function namedship-val once for each item of the array in theshipped field.

"Validate All":{ "Type": "Map", "InputPath": "$.detail", "ItemProcessor":{ "ProcessorConfig":{ "Mode": "INLINE" }, "StartAt": "Validate", "States":{ "Validate":{ "Type": "Task", "Resource": "arn:aws:states:::lambda:invoke", "OutputPath": "$.Payload", "Parameters":{ "FunctionName": "arn:aws:lambda:us-east-2:account-id:function:ship-val:$LATEST" }, "End": true } } }, "End": true, "ResultPath": "$.detail.shipped", "ItemsPath": "$.shipped"}

Each iteration of theMap state sends an item in the array, selected with theItemsPath field, as input to theship-val Lambda function. The following values are an example of input theMap state sends to an invocation of the Lambda function:

{ "prod": "R31", "dest-code": 9511, "quantity": 1344}

When complete, the output of theMap state is a JSON array, where each item is the output of an iteration. In this case, this array contains the output of theship-val Lambda function.

Inline Map state example withItemSelector

Suppose that theship-val Lambda function in the previous example also needs information about the shipment's courier. This information is in addition to the items in the array for each iteration. You can include information from the input, along with information specific to the current iteration of theMap state. Note theItemSelector field in the following example:

"Validate-All":{ "Type": "Map", "InputPath": "$.detail", "ItemsPath": "$.shipped", "MaxConcurrency": 0, "ResultPath": "$.detail.shipped","ItemSelector":{ "parcel.$": "$$.Map.Item.Value", "courier.$": "$.delivery-partner" }, "ItemProcessor":{ "StartAt": "Validate", "States":{ "Validate":{ "Type": "Task","Resource": "arn:aws:lambda:region:account-id:function:ship-val", "End": true } } }, "End": true}

TheItemSelector block replaces the input to the iterations with a JSON node. This node contains both the current item data from theContext object and the courier information from theMap state input'sdelivery-partner field. The following is an example of input to a single iteration. TheMap state passes this input to an invocation of theship-val Lambda function.

{ "parcel":{ "prod": "R31", "dest-code": 9511, "quantity": 1344 }, "courier": "UQS"}

In the previousInline Map state example, theResultPath field produces output in the same format as the input. However, it overwrites thedetail.shipped field with an array in which each element is the output of each iteration'sship-val Lambda invocation.

For more information about using theInline Map state state and its fields, see the following.

InlineMap state input and output processing

For a givenMap state,InputPath selects a subset of the state's input.

The input of aMap state must include a JSON array. TheMap state runs theItemProcessor section once for each item in the array. If you specify theItemsPath field, theMap state selects where in the input to find the array to iterate over. If not specified, the value ofItemsPath is$, and theItemProcessor section expects that the array is the only input. If you specify theItemsPath field, its value must be aReference Path. TheMap state applies this path to the effective input after it applies theInputPath. TheItemsPath must identify a field whose value is a JSON array.

The input to each iteration, by default, is a single element of the array field identified by theItemsPath value. You can override this value with theItemSelector (Map) field.

When complete, the output of theMap state is a JSON array, where each item is the output of an iteration.

For more information about Inline Map state inputs and outputs, see the following:

Map
Distributed mode

[8]
ページ先頭

©2009-2025 Movatter.jp