Using Inline Map state to repeat an action
This tutorial helps you get started with using the Map
state in Inline mode.
You use the Inline Map state in your workflows to repeatedly perform an action. For more
information about Inline mode, see Map
state in Inline mode.
In this tutorial, you use the Inline Map state to repeatedly generate version 4 universally
unique identifiers (v4 UUID). You start by creating a workflow that contains two Pass states and an Inline Map state in the
Workflow Studio. Then, you configure the input and output, including the input JSON array for the
Map
state. The Map
state returns an output array that contains
the v4 UUIDs generated for each item in the input array.
Currently, Inline mode of the Map
state is available in Commercial Regions only. For information about including Map
state in your workflows, see Map.
Contents
Step 1: Create the workflow prototype
In this step, you create the prototype for your workflow using Workflow Studio. Workflow Studio is a visual workflow designer available in the Step Functions console. You’ll choose the required states from the Flow tab and use the drag and drop feature of Workflow Studio to create the workflow prototype.
Open the Step Functions console
and choose Create state machine. On the Choose authoring method page, keep the default selections of Design your workflow visually and Standard, and then choose Next.
In Workflow Studio, from the Flow tab, drag a Pass state and drop it to the empty state labelled Drag first state here.
Drag a Map state and drop it below the Pass state. Rename the Map state to
Map demo
.Drag a Pass state and drop it inside of the Map demo state.
Rename the Pass state to
Generate UUID
.
Step 2: Configure input and output
In this step, you configure input and output for all the states in your workflow prototype. First, you inject some fixed data into the workflow using the first Pass state. This Pass state passes on this data as input to the Map demo state. Within this input, you specify the node that contains the input array the Map demo state should iterate over. Then you define the step that the Map demo state should repeat to generate the v4 UUIDs. Finally, you configure the output to return for each repetition.
Choose the first Pass state in your workflow prototype. In the Output tab, enter the following under Result:
{ "foo": "bar", "colors": [ "red", "green", "blue", "yellow", "white" ] }
Choose the Map demo state and in the Configuration tab, do the following:
Choose Provide a path to items array.
Specify the following reference path to select the node that contains the input array:
$.colors
Choose the Generate UUID state and in the Input tab, do the following:
Choose Transform input with Parameters.
Enter the following JSON input to generate the v4 UUIDs for each of the input array items. You use the
States.UUID
intrinsic function to generate the UUIDs.{ "uuid.$": "States.UUID()" }
For the Generate UUID state, choose the Output tab and do the following:
Choose Filter output with OutputPath.
Enter the following reference path to select the JSON node that contains the output array items:
$.uuid
Step 3: Review the auto-generated Amazon States Language definition
As you drag and drop states from the Flow panel onto the canvas, Workflow Studio automatically composes the Amazon States Language definition of your workflow in real-time. You can edit this definition as required.
-
(Optional) Choose Definition on the Inspector panel and view the state machine definition.
The following example shows the automatically generated Amazon States Language definition for your workflow.
{ "Comment": "Using Map state in Inline mode", "StartAt": "Pass", "States": { "Pass": { "Type": "Pass", "Next": "Map demo", "Result": { "foo": "bar", "colors": [ "red", "green", "blue", "yellow", "white" ] } }, "Map demo": { "Type": "Map", "ItemsPath": "$.colors", "ItemProcessor": { "ProcessorConfig": { "Mode": "INLINE" }, "StartAt": "Generate UUID", "States": { "Generate UUID": { "Type": "Pass", "End": true, "Parameters": { "uuid.$": "States.UUID()" }, "OutputPath": "$.uuid" } } }, "End": true } } }
-
Choose Next.
-
On the Review generated code page, review your workflow's Amazon States Language definition. If needed, you can make additional changes under Definition.
-
Choose Next.
-
Enter a name for your workflow. For example, enter
InlineMapDemo
. -
Keep all the default selections on the Specify state machine settings page and choose Create state machine.
Step 4: Start a new execution
State machine executions are instances where you run your workflow to perform tasks.
-
On the InlineMapDemo page, choose Start execution.
-
(Optional) To identify your execution, you can specify a name for it in the Name box. By default, Step Functions automatically generates a unique execution name.
Note Step Functions allows you to create names for state machines, executions, activities, and labels that contain non-ASCII characters. These non-ASCII names don't work with Amazon CloudWatch. To ensure that you can track CloudWatch metrics, choose a name that uses only ASCII characters.
-
Choose Start execution.
-
The Step Functions console directs you to a page that's titled with your execution ID. On this page, you can review the results of your new execution. Under Details, you can see your execution ARN and the execution status of your state machine. To view the execution input and output side-by-side, choose Execution input and output. Under Output, view the output array returned by the
Map
state. The following is an example of the output array:[ "a85cbc7b-4e65-4ac2-97af-80ed504adc1d", "b05bca11-d481-414e-aa9a-88285ec6590d", "f42d59f7-bd32-480f-b270-caddb518ce2a", "15f18616-517d-4b69-b7c3-bf22222d2efd", "690bcfee-6d58-408c-a6b4-1995ccafdbd2" ]