2

I have a setup where I need to iterate through some array and perform a few steps for each item in the array.

These steps that are to be performed on each item, are dependent on each other and are mainly lambda calls/tasks.

Naturally, the Map state fits the use case best. But I want to know what happens if I define a ResultPath for each step inside the iterator. Is it going to conflict with each other while these items are processed in parallel or that is taken care of?

Imagine in the below example, I have a ResultPath for validating $.validateResult. Is $ in this context referring to the context inside the iterator and is per object, or is it still referring to the global object, and all my iterations are writing to the same place? For example, If I have another step after validateResult that needs to consume this data, will it reliably be able to access the result from the previous step in this iteration, or will my ResultPath's collide across different iterations as a Map state works concurrently.

Hope I was able to explain it.

  "Validate-All": {
  "Type": "Map",
  "InputPath": "$.detail",
  "ItemsPath": "$.shipped",
  "MaxConcurrency": 0,
  "Iterator": {
    "StartAt": "Validate",
    "States": {
      "Validate": {
        "Type": "Task",
    "Resource": "arn:aws:lambda:us-east-1:123456789012:function:ship-val",
        "End": true
        "ResultPath": "$.validateResult"
      }
    }
  },
  "ResultPath": "$.detail.shipped",
  "End": true
}

1 Answer 1

6

ResultPath inside the map iterator only belongs to the task within the map. It is not going to mix up across iterations or with original input.

Here is a sample Map

{
   "StartAt":"Dummy Step 1 Output",
   "States":{
      "Dummy Step 1 Output":{
         "Type":"Pass",
         "Result":[
            {
               "iter":1
            },
            {
               "iter":2
            }
         ],
         "ResultPath":"$.inputForMap",
         "Next":"loop on map"
      },
      "loop on map":{
         "Type":"Map",
         "ResultPath":"$.mapOutput",
         "Next":"Step three",
         "Iterator":{
            "StartAt":"Step 2 - Looping on map",
            "States":{
               "Step 2 - Looping on map":{
                  "Type":"Pass",
                  "Result":{
                     "outputOfStepWithInMap":"This is output of step within map"
                  },
                  "ResultPath":"$.validateResult",
                  "End":true
               }
            }
         },
         "ItemsPath":"$.inputForMap",
         "MaxConcurrency":1
      },
      "Step three":{
         "Type":"Pass",
         "Next":"End of Step Function"
      },
      "End of Step Function":{
         "Type":"Pass",
         "End":true
      }
   }
}

enter image description here

Map Step Input:

{
  "Comment": "Insert your JSON here",
  "inputForMap": [
    {
      "iter": 1
    },
    {
      "iter": 2
    }
  ]
}

Map Step Output:

{
  "Comment": "Insert your JSON here",
  "inputForMap": [
    {
      "iter": 1
    },
    {
      "iter": 2
    }
  ],
  "mapOutput": [
    {
      "iter": 1,
      "validateResult": {
        "outputOfStepWithInMap": "This is output of step within map"
      }
    },
    {
      "iter": 2,
      "validateResult": {
        "outputOfStepWithInMap": "This is output of step within map"
      }
    }
  ]
}

If we noticed validateResult is present in each element of map output array.

Sign up to request clarification or add additional context in comments.

1 Comment

I took one of my other answers and updated for this use case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.