profile
viewpoint

Ask questionsRunLambdaTask with outputPath not working

<!-- description of the bug: -->

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

<!-- what is the error message you are seeing? -->

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
aws/aws-cdk

Answer questions eikeon

I should have stared at https://docs.aws.amazon.com/step-functions/latest/dg/concepts-input-output-filtering.html longer. Had it in my head that the $outputPath happens before not after the $resultPath in that diagram.

But I'm still not able to replicate the TaskOutput I get with InvokeFunction when using RunLambdaTask. Attempt 1)

--- a/lib/getobject-statemachine.ts
+++ b/lib/getobject-statemachine.ts
@@ -48,6 +48,7 @@ export class GetObjectStateMachine extends cdk.Construct {

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

results in LambdaFunctionSucceeded with output:

{
  "output": {
    "Done": true,
    "Next": null,
    "BitsFetched": 0
  }
}

followed by ExecutionFailed with:

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

Attempt 2)

--- a/lib/getobject-statemachine.ts
+++ b/lib/getobject-statemachine.ts
@@ -48,6 +48,7 @@ export class GetObjectStateMachine extends cdk.Construct {
 
         const getObject = new sfn.Task(this, "Get Object", {
             task: new tasks.InvokeFunction(getObjectLambda, {}),
+            outputPath: "$.GetObjectResult",
             resultPath: "$.GetObjectResult",
         });

followed by TaskStateExited with:

{
  "name": "Get Object",
  "output": {
    "Done": true,
    "Next": null,
    "BitsFetched": 0
  }
}

where as with the InvokeFunction the task state exited with:

{
  "name": "Get Object",
  "output": {
    "ParentContentID": "AQERFLelzPqbNGewZ3/CDNW/o/ZzuA4U",
    "Hash": "ERTg6jh13sV9G3ILH6qyChVfn4i2Bg==",
    "URL": "https://archive.org/download/snowyforluck00good/snowyforluck00good_metasource.xml",
    "Size": 0,
    "PartInfo": null,
    "GetObjectResult": {
      "Done": true,
      "Next": null,
      "BitsFetched": 0
    }
  }
}
useful!

Related questions

Issues compiling CDK projects ("TS2300: Duplicate identifier 'IteratorResult'")
cli: cdk deploy issue hot 3
Subnet selection returns more than one per AZ hot 2
cli: synth fails if cdk.out does not exist hot 2
Default policy are getting creating even when Managed policy were created in the Role hot 1
Python dependency libraries are set to latest hot 1
using json instead of a string as context in cdk.json hot 1
Attaching Managed Policy to Role failing hot 1
Access denied when adding an event notification to an existing s3 bucket hot 1
Unable to create CfnSpotFleet using Python hot 1
DBClusterParameterGroup not found: default.aurora5.6 hot 1
aws-ecs: Cannot deploy fargate services with ECR images hot 1
ecs_patterns.ApplicationLoadBalancedFargateService should allow specifying healthCheck path - aws-cdk hot 1
CodeCommitSourceAction tries to add a policy to an imported role hot 1
Using getAtt that returns a list within a string that is joined in the generated template throws an error hot 1
Github User Rank List