2

Issue: Can someone please point me in the right direction as to what I am doing incorrectly with my state syntax? My lambda function is unable to read a parallel task output, but succeeds in running. Here's what the output looks like (and step input and state syntax at the very bottom):

"Payload": {
    "brand_iteration_list": [],
    "user_msg": "It did something!"
}

Context: I am trying to pass the results of a Parallel task into a Lambda function to combine the inputs and generate a new array - which I want to iterate over afterwards. My parallel task consist of 2 lambda functions which:

  • returns an array consisting of brand objects
  • returns an array of brand properties that each brand needs an iteration for

My lambda function takes the output of the parallel task (an array) and then combines the two, iterating over each brand, then creating an object of each brand with the brand properties, and appending it to a "final array" to be returned at the end via JSON object.

  • Note 1: When I take the Step Input and test my lambda function directly, it is outputting as expected.
  • Note 2: When that same function runs through the Step Functions, it appears that the output is not being passed. Therefore, that is why I believe my state syntax is incorrectly setup.

State Syntax:

{
"Comment": "Generate Token",
"StartAt": "Get_Token",
"States": {
  "Get_Token": {
    "Type": "Task",
    "Resource": "arn:aws:states:::lambda:invoke",
    "Parameters": {
      "FunctionName": "arn:aws:lambda..."
    },
    "Next": "Get_Brand_List_and_Brand_Props"
  },
  "Get_Brand_List_and_Brand_Props": {
    "Type": "Parallel",
    "Next": "Create_Brand_Iteration_Array",
    "InputPath": "$.Payload",
    "Parameters": {
      "Input.$": "$"
    },
    "Branches": [
      {
        "StartAt": "Get_Brand_List",
        "States": {
          "Get_Brand_List": {
            "Type": "Task",
            "Resource": "arn:aws:lambda...",
            "End": true
          }
        }
      },
      {
        "StartAt": "Get_Brand_Props",
        "States": {
          "Get_Brand_Props": {
            "Type": "Task",
            "Resource": "arn:aws:lambda...",
            "End": true
          }
        }
      }
    ]
  },
  "Create_Brand_Iteration_Array": {
    "Type": "Task",
    "Resource": "arn:aws:states:::lambda:invoke",
    "InputPath": "$",
    "Parameters": {
      "FunctionName": "arn:aws:lambda..."
    },
    "Next": "Retrieve_Brand_Info"
  },
  "Retrieve_Brand_Info": {
    "Type": "Pass",
    "End": true
  }
}

}

Step Input going into Lambda that returns empty array []:

[
    {
        "brand_list": [
            {
                "name": "..."
            },
            {
                "name": "..."
            },
            {
                "name": "..."
            },
                "user_msg": "Brand list retrieved"
            }
    },
    {
        "brand_props: [
            {
                "prop": "...",
                "prop2": "..."
            },
            {
                "prop": "...",
                "prop2": "..."
            },
            {
                "prop": "...",
                "prop2": "..."
            },
                "user_msg": "Brand props retrieved"
            }
    }
]
7
  • 1
    Can you confirm the exact output of the parallel task in the 'Execution Details' in the AWS Console (as well as the input to the 'Create_Brand_Iteration_Array') matches what youre sending when directly invoking the lambda ? Also double check the inputs/outputs for each ID in the 'Execution History' section. I've been able to find some additional useful info in there when debugging. Commented Jul 11, 2022 at 18:14
  • 1
    Thank you for the follow-up @deric4! I've double-checked the execution details and everything looks to be in working order. I continued testing and realized that my event was not being handled at all - meaning that AWS step functions must receive an object in order for it to be registered as a proper "event". Right now, I'm currently trying to turn my array of objects [{},{}] into one standalone object {} when moving into the 'Create_Brand_Iteration_Array' step to see if this resolves the issue. Commented Jul 11, 2022 at 18:38
  • I used a Pass state to turn the array into an object, but the next task state is still not ingesting the input correctly. I am pretty stumped at this point... Commented Jul 11, 2022 at 19:23
  • 1
    when you print(event.get('body')) in your lambda function, does it match the input from as whats the AWS console? Commented Jul 11, 2022 at 19:51
  • 1
    ah, just saw your latest response about the fix. actually you can still use what you had initially, you just need to add the "Payload.$": "$", to your Parameters. I typically prefer to use this over the specifying the arn in the resource, since you can dynamically set the function{name,arn,version} etc if needed Commented Jul 11, 2022 at 19:56

0

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.