aws / aws/aws-cdk

aws_apigateway: LambdaRestApi does not respect the proxy: false property

Open
#21,787 7 comments 4 reactions 0 assignees View on GitHub
@aws-cdk/aws-apigateway bug effort/small p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### Describe the bug

Hello! I want to use the LambdaRestApi construct and use a non-proxy integration. Therefore, I set the proxy prop to false as shown in the [LambdaRestApi documentation](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.LambdaRestApi.html) to create an API GW resource and POST method.

```typescript
const gateway = new apigateway.LambdaRestApi(
this,
"APIGW_MobileApiTestEndpoint",
{
handler: mobileApi_test_Lambda,
endpointConfiguration: {
types: [apigateway.EndpointType.REGIONAL],
},
proxy: false,
}
);

const testResource = gateway.root.addResource("test");
testResource.addMethod("POST");
```

Trouble is, CDK deploys the stack with the API Gateway Integration Request boolean 'Use Lambda Proxy Integration' set to True. Testing this produces the result you would expect for a Lambda that isn't expecting a proxy request ... it fails. When testing that Resource using the console, the API Gateway Test Log also shows that it's sending the full proxy payload. And you can plainly see it is configured as a LAMBDA_PROXY in the method’s Integration Request window in the console:

Screen Shot 2022-08-26 at 7 39 50 PM

This bug was reported back in February 2021 in issue [#13026](https://github.com/aws/aws-cdk/issues/13026). At that time @nija-at tested it, and said it was working normally. However, in his test he actually demonstrated that this is a bug ... he just didn't seem to realize it. In his sample nodejs code, @nija-at is returning the status code in the response `return { statusCode: 200, body: "Hello world!" }` which is what you have to do when the lambda integration IS configured to be a proxy, even though he set Proxy to false in his test. In a non-proxy lambda integration, you don't return the status code. Others have reported this bug on ticket 13026 as well.

I would greatly appreciate it if we can get a fix for this!

### Expected Behavior

I expect the 'proxy: false' property to be respected by the LambdaRestApi construct.

### Current Behavior

The 'proxy: false' property of the LambdaRestApi construct is not respected.

### Reproduction Steps

Shown in the description above.

### Possible Solution

_No response_

### Additional Information/Context

_No response_

### CDK CLI Version

2.39.0

### Framework Version

2.39.0

### Node.js Version

14.17.0

### OS

OS X Monterey 12.1

### Language

Typescript

### Language Version

3.9.7

### Other information

_No response_

Contributor guide

Open the contributing guide

Research direction

Start at the LambdaRestApi construct and trace how its proxy property configures the API Gateway method integration. Use the reproduction in the issue with proxy: false and a non-proxy Lambda, then verify that the deployed method no longer uses LAMBDA_PROXY or sends a proxy payload.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.