aws / aws/aws-cdk

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

Open
#28,310 2 comments 0 reactions 0 assignees View on GitHub
@aws-cdk/aws-lambda bug effort/medium p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### 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):

```ts
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"`

```js
null
```

- `resultPath: "$.Result"`

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

- `payloadResponseOnly: true, resultPath: "$.Result"`

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

- `resultPath: "$.Result",outputPath: "$.Payload"`

```json
{
/* 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:
```ts
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.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the supplied two-Lambda stack with StepFunctionsIntegration.startExecution and each listed resultPath/outputPath combination. Trace how the integration handles Result and Payload, then verify that the expected response data is preserved consistently for those cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, typescript
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.