aws-cdk: RunLambdaTask with outputPath not working

outputPath when used with RunLambdaTask is not working as documented. In the step functions overview under Lambda example

“The following snippet invokes a Lambda and sets the task output to only include the Lambda function response.”

new sfn.Task(this, 'Invoke and set function response as task output', {
  task: new tasks.RunLambdaTask(myLambda, {
    payload: sfn.TaskInput.fromDataAt('$'),
  }),
  outputPath: '$.Payload',
});

Reproduction Steps

Starting from a working tasks.InvokeFunction:

<!--
minimal amount of code that causes the bug (if possible) or a reference:
-->

         const getObject = new sfn.Task(this, "Get Object", {
-            task: new tasks.RunLambdaTask(getObjectLambda, {}),
-            outputPath: "$.Payload",
+            task: new tasks.InvokeFunction(getObjectLambda, {}),
             resultPath: "$.GetObjectResult",
         });

Also tried outputPath: “$.output.Payload” with same result.

Error Log

TaskSucceeded with:

{
  "resourceType": "lambda",
  "resource": "invoke",
  "output": {
    "ExecutedVersion": "$LATEST",
    "Payload": {
      "Done": true,
      "Next": null,
      "BitsFetched": 0
    },
    "SdkHttpMetadata": {
      "HttpHeaders": {
        "Connection": "keep-alive",
        "Content-Length": "41",
        "Content-Type": "application/json",
        "Date": "Thu, 30 Apr 2020 00:36:36 GMT",
        "X-Amz-Executed-Version": "$LATEST",
        "x-amzn-Remapped-Content-Length": "0",
        "x-amzn-RequestId": "f1e1c5df-4740-4389-8230-2c495c5cd829",
        "X-Amzn-Trace-Id": "root=1-5eaa1d94-16cf39fcb6ea5d8bb11bd635;sampled=0"
      },
      "HttpStatusCode": 200
    },
    "SdkResponseMetadata": {
      "RequestId": "f1e1c5df-4740-4389-8230-2c495c5cd829"
    },
    "StatusCode": 200
  }
}

followed by `ExecutionFailed` with:

```json
{
  "error": "States.Runtime",
  "cause": "An error occurred while executing the state 'Get Object' (entered at the event id #2). Invalid path '$.Payload' : No results for path: $['Payload']"
}

{



### Environment

  - **CLI Version      :** 1.36.1
  - **Framework Version:** 1.36.1
  - **OS               :** macOS Catalina 10.15.5 Beta (19F62f)
  - **Language         :** Typescript

### Other

<!-- e.g. detailed explanation, stacktraces, related issues, suggestions on how to fix, links for us to have context, eg. associated pull-request, stackoverflow, gitter, etc -->




--- 

This is :bug: Bug Report

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 15 (10 by maintainers)

Commits related to this issue

Most upvoted comments

In #9022 we introduced a flag payloadResponseOnly to the LambdaInvoke class which succeeded RunLambdaTask to request the legacy behaviour where Lambda’s function result only is the state output and no other metadata is included.

The legacy Lambda integration with Step Functions does not support callbacks (.sync) and is request response only. It does offer the benefit of a simpler experience for users that just want Lambda’s results to become the state output and for the Lambda to run synchronously.

Yep; the addition of a few .Payloads elsewhere in my step functions and no need for workarounds. So maybe just a note along side the deprecated notice of InvokeFunction of what options lie ahead. If I would have started with RunLambdaFunction I would not have been trying to preserve that exact behavior so hard