aws / aws/aws-cdk

(aws-apigateway): `StepFunctionsRestApi` does not pass on `path`

Open
#27,309 2 comments 1 reaction 0 assignees View on GitHub
@aws-cdk/aws-apigateway 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

The construct `StepFunctionsRestApi` seems to be buggy regarding `path` handling.

### Expected Behavior

When using `StepFunctionsRestApi` with `path: true` I expect my underlying Step Function to receive the path.

### Current Behavior

Passing a path (also tried different depths combinations like: `...prod/users/4` or `.../prod/12`) leads to a `{"message":"Missing Authentication Token"}`

see: `curl -X GET "https://XXXXXXXX.execute-api.eu-central-1.amazonaws.com/prod/123"
{"message":"Missing Authentication Token"}`

### Reproduction Steps

deploy this (almost) minimal example:

```ts
const successState = new Pass(this, "SuccessState");

const stateMachine = new StateMachine(this, "CrudStateMachine", {
definitionBody: DefinitionBody.fromChainable(successState),
timeout: Duration.minutes(5),
stateMachineType: StateMachineType.EXPRESS,
comment: "This state machine returns an employee entry from DynamoDB",
logs: {
destination: new LogGroup(this, "StateMachineLogs", {
retention: RetentionDays.ONE_DAY,
}),
level: LogLevel.ALL,
includeExecutionData: true,
},
});

new StepFunctionsRestApi(this, "StepFunctionsRestApi", {
stateMachine,
path: true,
requestContext: {
httpMethod: true,
},
});
```

and send a similar request to the created API:
`curl -X GET "https://${apigatewayid}.execute-api.eu-central-1.amazonaws.com/prod/123"`

### Possible Solution

_No response_

### Additional Information/Context

I can workaround the problem by creating a proxy integration manually on the API but I guess that is not the idea here.

see

```
const sfnApi = new StepFunctionsRestApi(this, 'StepFunctionsRestApi', {
deploy: true,
stateMachine: sfn,
});

sfnApi.root.addProxy({
defaultIntegration: StepFunctionsIntegration.startExecution(sfn, {
path: true,
querystring: true,
}),
anyMethod: true,
});

sfnApi.root.addResource('testpath').addProxy({
defaultIntegration: StepFunctionsIntegration.startExecution(sfn, {
path: true,
querystring: true,
}),
anyMethod: true,
});
```

Does the current implementation on the vtl `packages/@aws-cdk/aws-apigateway/lib/integrations/stepfunctions.vtl` only work for key value pairs (regarding paths)?

### CDK CLI Version

2.97.0

### Framework Version

2.97.0

### Node.js Version

v18.14.0

### OS

macos 14 (also happened on 13)

### Language

Typescript

### Language Version

^4.8.3

### Other information

_No response_

Contributor guide

Open the contributing guide

Research direction

The entry point is StepFunctionsRestApi and the integration template is packages/@aws-cdk/aws-apigateway/lib/integrations/stepfunctions.vtl. Reproduce the reported GET request, then trace how path: true is rendered; done means a request such as /prod/123 no longer returns Missing Authentication Token and the underlying Step Function receives the path.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.