3

I have created a basic state machine that runs a lambda and then uses the output of that lambda to decide a choice. However, I have not been able to receive the output from the lambda function because it keeps returning a null payload. I have tried running the lambda alone from the lambda console and it runs fine (including with the expected return). However, within the step function, the task at least, is returning null for the Payload output.

Here is the definition of my state-machine:

{
  "StartAt": "ValidateWorkcellConfigTask",
  "States": {
    "ValidateWorkcellConfigTask": {
      "Next": "ConfigValidationTypeChoiceState",
      "Parameters": {
        "FunctionName": "ValidateWorkcellConfig",
        "InvocationType": "Event",
        "Payload.$": "$"
      },
      "OutputPath": "$",
      "Type": "Task",
      "Resource": "arn:aws:states:::lambda:invoke",
      "TimeoutSeconds": 15
    },
    "ConfigValidationTypeChoiceState": {
      "Type": "Choice",
      "Comment": "Forwards a VALID workflow config to the Provisioning Workflow or Relays the INVALID workflow config for logging",
      "Choices": [
        {
          "Variable": "$.uuid",
          "StringEquals": "SEA90-1",
          "Next": "endState"
        },
        {
          "Variable": "$.validConfig",
          "StringEquals": "SEA90-1",
          "Next": "SuccessRelayTask"
        }
      ]
    },
    "endState": {
      "Type": "Pass",
      "End": true
    },
    "SuccessRelayTask": {
      "End": true,
      "Parameters": {
        "FunctionName": "StatusRelayHandler",
        "InvocationType": "Event",
        "Payload.$": "$"
      },
      "OutputPath": "$",
      "Type": "Task",
      "Resource": "arn:aws:states:::lambda:invoke",
      "ResultPath": "$",
      "TimeoutSeconds": 15
    }
  }
}

And here is the output of the lambda task execution:

{
  "name": "ValidateWorkcellConfigTask",
  "output": {
    "Payload": null,
    "SdkHttpMetadata": {
      "AllHttpHeaders": {
        "x-amzn-Remapped-Content-Length": [
          "0"
        ],
        "Connection": [
          "keep-alive"
        ],
        "x-amzn-RequestId": [
          "4452a8d2-e607-4ae6-943c-9478b0f59ce0"
        ],
        "Content-Length": [
          "0"
        ],
        "Date": [
          "Sat, 16 Jan 2021 09:22:48 GMT"
        ],
        "X-Amzn-Trace-Id": [
          "root=1-6002b068-52fb3d1f60f20d3e10804f96;sampled=0"
        ]
      },
      "HttpHeaders": {
        "Connection": "keep-alive",
        "Content-Length": "0",
        "Date": "Sat, 16 Jan 2021 09:22:48 GMT",
        "x-amzn-Remapped-Content-Length": "0",
        "x-amzn-RequestId": "4452a8d2-e607-4ae6-943c-9478b0f59ce0",
        "X-Amzn-Trace-Id": "root=1-6002b068-52fb3d1f60f20d3e10804f96;sampled=0"
      },
      "HttpStatusCode": 202
    },
    "SdkResponseMetadata": {
      "RequestId": "4452a8d2-e607-4ae6-943c-9478b0f59ce0"
    },
    "StatusCode": 202
  },
  "outputDetails": {
    "truncated": false
  }
}

Notice how the payload is null... that is causing the next task to fail because it receives a null input. I've already played around with OutputPath, ResultPath, and InputPath but have never been able to return something from the lambda task.

The lambda itself is written in Java and return a String. It implements this interface:

... implements RequestHandler<WorkcellConfig, String>

3
  • The state machine definition contains "FunctionName": "ValidateWorkcellConfig" - is this also in your real configuration? Because you should define the function ARN here, not just a function name. Commented Jan 16, 2021 at 11:07
  • Can you share your lambda code? It looks like you don't return anything from the first invocation lumigo.io/blog/… Look here for a tutorial about how to set a step function Commented Jan 17, 2021 at 15:32
  • Hi, I have the same issue. Could you share how did you solve that problem? Commented Jul 15, 2021 at 17:29

2 Answers 2

3

I think the problem that you have may be due to the Invocation Type, you set it as event (asynchronously) so you give no time to the lambda function to return the result payload. Try changing it to RequestResponse to run it synchronously (this is the default type, so you can omit this parameter).

You can check more details about Invocation Type here.

The code should look like this:

{
    "StartAt": "ValidateWorkcellConfigTask",
    "States": {
    "ValidateWorkcellConfigTask": {
        "Next": "ConfigValidationTypeChoiceState",
        "Parameters": {
        "FunctionName": "ValidateWorkcellConfig",
        "Payload.$": "$"
        },
        "OutputPath": "$",
        "Type": "Task",
        "Resource": "arn:aws:states:::lambda:invoke",
        "TimeoutSeconds": 15
    },
    "ConfigValidationTypeChoiceState": {
        "Type": "Choice",
        "Comment": "Forwards a VALID workflow config to the Provisioning Workflow or Relays the INVALID workflow config for logging",
        "Choices": [
        {
            "Variable": "$.uuid",
            "StringEquals": "SEA90-1",
            "Next": "endState"
        },
        {
            "Variable": "$.validConfig",
            "StringEquals": "SEA90-1",
            "Next": "SuccessRelayTask"
        }
        ]
    },
    "endState": {
        "Type": "Pass",
        "End": true
    },
    "SuccessRelayTask": {
        "End": true,
        "Parameters": {
        "FunctionName": "StatusRelayHandler",
        "Payload.$": "$"
        },
        "OutputPath": "$",
        "Type": "Task",
        "Resource": "arn:aws:states:::lambda:invoke",
        "ResultPath": "$",
        "TimeoutSeconds": 15
    }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

1

I just had this same problem, which was because my function definition wasn't correct. Lambdas need to return a promise, even if they're not doing anything async.

so:

export const handler = (event: InputParams) => {
  return { hello: "world" }
};

does not work, whereas this does work:

export const handler = async (event: InputParams) => {
  return { hello: "world" }
};

Comments

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.