Search code examples
amazon-web-servicesaws-lambdaaws-step-functions

AWS Step Function map task not passing input to starting task


I am observing that my Step Function map is not passing input to the the task's lambda. Does anyone know how to fix this? When I run the step function, I can see the input is being correctly passed to the task, but nothing shows for the event variable in the lambda function.

          "push_stats_to_prometheus": {
            "Type": "Map",
            "InputPath": "$.Payload",
            "ItemsPath": "$.body",
            "MaxConcurrency": 10,
            "Iterator": {
              "StartAt": "push_stats",
              "States": {
                "push_stats": {
                  "Type": "Task",
                  "Resource": "arn:aws:states:::lambda:invoke",
                  "Parameters": {
                    "FunctionName": "${self:functions.push_stats_to_prometheus.name}"
                  },
                  "End": true
                }
              }
            },
            "ResultPath": "$.Payload.body",
            "Next": "push_score_to_prometheus"
          }

Solution

  • Looking at the Lambda service integration under supported parameters we can see that Payload is the input to the function and you have not specified this in Parameters. Changing your Lambda Task State JSON as follows should pass the input to the State as the Input to the Lambda function:

    "push_stats": {
      "Type": "Task",
      "Resource": "arn:aws:states:::lambda:invoke",
      "Parameters": {
        "Payload.$": "$",  
        "FunctionName": "${self:functions.push_stats_to_prometheus.name}"
      },
      "End": true
    }
    

    Also check out my previous answer on different methods to invoke a Lambda function using Step Functions, I think option 2 (Lambda ARN as the Resource) might be a bit easier to use.