Search code examples
aws-step-functions

AWS Step functions remove payload attribute from lambda output


I have a lambda that produces an array of json objects. I want the lambda result passed to a step function under a given attribute name.

Input to task that runs lambda:

{
"foo": "abc",
"bar": "def"
}

Output I want

{
"foo": "abc",
"bar": "def",
"lambdaOutput": [
  {...},
  {...}
]
}

I thought ResultSelector + ResultPath is supposed to solve this problem but I am stuck. I tried

"ResultSelector": {
        "lambdaOutput.$": "$.Payload",
      },
      "ResultPath": "$.lambdaOutput"

But this just creates a nested structure

{
"foo": "abc",
"bar": "def",
"lambdaOutput": 
    "lambdaOutput: {
    [ 
      {...},
      {...}
    ]
    }
}

What am i missing?


Solution

  • Not sure how to do it from console, but from CDK, you can specify payloadResponseOnly

    https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_stepfunctions_tasks.LambdaInvoke.html#payloadresponseonly