Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws-cdk-lib/aws-apigateway: Step Functions Integration resultPath and outputPath issue #28310

Open
rafaelrcamargo opened this issue Dec 8, 2023 · 2 comments
Labels
@aws-cdk/aws-lambda Related to AWS Lambda bug This issue is a bug. effort/medium Medium work item – several days of effort p2

Comments

@rafaelrcamargo
Copy link
Contributor

Describe the bug

When configuring Step Functions Integration in the CDK with different combinations of resultPath and outputPath, the response data behaves inconsistently, resulting in unexpected values for "Result" and "Payload".

Expected Behavior

The integration should consistently provide both "Result" and "Payload" in the response data when defining resultPath and outputPath.

Current Behavior

With this code (Simplified version):

const machineDefinition = new LambdaInvoke(this, "exampleFnInvokeTask", { lambdaFunction: exampleFn })
  .next(new LambdaInvoke(this, "exampleFnInvokeTask2", { lambdaFunction: exampleFn2 }))

const stateMachine = new sfn.StateMachine(this, "StateMachine", {
  stateMachineName: "stateMachine",
  stateMachineType: sfn.StateMachineType.EXPRESS,
  definitionBody: sfn.DefinitionBody.fromChainable(machineDefinition)
})

const stepFunctionIntegration = StepFunctionsIntegration.startExecution(stateMachine,{})

const callbackEnd = api.root.addResource("callback")
callbackEnd.addMethod("POST", stepFunctionIntegration)

The expected return would be the full response with the "Payload" property with the data returned from the second function but this does not happen, depending on the combination of properties the response behaves in a weird way.

Cases:

  • outputPath: "$.Payload"

    null  
  • resultPath: "$.Result"

    {
      "ExecutedVersion": "$LATEST",
      "Payload": { /* Expected data */ },
      "SdkHttpMetadata": { ... },
      "SdkResponseMetadata": { ... },
      "StatusCode": 200,
      "Result": {
        "ExecutedVersion": "$LATEST",
        "Payload": null,
        "SdkHttpMetadata": { ... },
        "SdkResponseMetadata": { ... },
        "StatusCode": 200
      }
    }
  • payloadResponseOnly: true, resultPath: "$.Result"

    {
      "ExecutedVersion": "$LATEST",
      "Payload": { /* Expected data */ },
      "SdkHttpMetadata": { ... },
      "SdkResponseMetadata": { ... },
      "StatusCode": 200,
      "Result": null
    }
  • resultPath: "$.Result",outputPath: "$.Payload"

    {
      /* Expected data */
    }

It seems like if the response is not changed or nothing is added, the return get's nulled out, but if only by adding "Result" as a property, the "Payload" gets populated.

Reproduction Steps

2 Lambdas:

  1. Return any data
  2. Returns the event from the first Lambda

This stack:

const machineDefinition = new LambdaInvoke(this, "exampleFnInvokeTask", { lambdaFunction: exampleFn })
  .next(new LambdaInvoke(this, "exampleFnInvokeTask2", { lambdaFunction: exampleFn2 }))

const stateMachine = new sfn.StateMachine(this, "StateMachine", {
  stateMachineName: "stateMachine",
  stateMachineType: sfn.StateMachineType.EXPRESS,
  definitionBody: sfn.DefinitionBody.fromChainable(machineDefinition)
})

const stepFunctionIntegration = StepFunctionsIntegration.startExecution(stateMachine,{})

const callbackEnd = api.root.addResource("callback")
callbackEnd.addMethod("POST", stepFunctionIntegration)

Possible Solution

Understand and maybe solve why this changes based on the different properties applied

Additional Information/Context

No response

CDK CLI Version

2.114.0 (build 12879fa)

Framework Version

No response

Node.js Version

v20.9.0

OS

Ubuntu 22.04.3 LTS

Language

TypeScript

Language Version

Typescript (3.9.10)

Other information

Ping me for any other info.

@rafaelrcamargo rafaelrcamargo added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Dec 8, 2023
@github-actions github-actions bot added the @aws-cdk/aws-lambda Related to AWS Lambda label Dec 8, 2023
@pahud
Copy link
Contributor

pahud commented Dec 12, 2023

Yes this is a little bit confusing. We probably should clarify this in the doc.

@pahud pahud added p2 effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Dec 12, 2023
@rafaelrcamargo
Copy link
Contributor Author

rafaelrcamargo commented Dec 19, 2023

Looking more in-depth on that I noted that:

With this Lambda handler: export function handler(event: any) { return event }

This returns just null (with a valid JSON as the input):

...
.next(
    new LambdaInvoke(this, "exampleFnInvoke", {
        lambdaFunction: exampleFn,
        payloadResponseOnly: true
    })
)

And this, returns the expect output:

...
.next(
    new LambdaInvoke(this, "exampleFnInvoke", {
        lambdaFunction: exampleFn,
        payloadResponseOnly: true,
        resultPath: sfn.JsonPath.DISCARD
    })
)

Am I missing something or is this expected?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-lambda Related to AWS Lambda bug This issue is a bug. effort/medium Medium work item – several days of effort p2
Projects
None yet
Development

No branches or pull requests

2 participants