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-apigateway) MockIntegrations with defaulCorsPreflightOptions return statusCode 500 #18297

Closed
Molaire opened this issue Jan 6, 2022 · 2 comments
Assignees
Labels
@aws-cdk/aws-apigateway Related to Amazon API Gateway bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. needs-cfn This issue is waiting on changes to CloudFormation before it can be addressed. needs-triage This issue or PR still needs to be triaged. p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@Molaire
Copy link

Molaire commented Jan 6, 2022

What is the problem?

If an API Gateway Resource allow CORS with defaultCorsPreflightOptions in its options, hitting its child methods that are MockIntegrations will fail with a Internal Error message (statusCode: 500)

This can be manually fixed by setting PassthroughBehavior.NEVER for the Integration request in CDK or the console.

Reproduction Steps

import {
    MockIntegration,
    PassthroughBehavior,
    RestApi,
} from "aws-cdk-lib/aws-apigateway";

const restApi = new RestApi(this, "testApi", {
  defaultCorsPreflightOptions: {
              allowOrigins: Cors.ALL_ORIGINS
          }
    })

const mockIntegration = new MockIntegration({
          integrationResponses: [{
              statusCode: '200',
              responseTemplates: {
                  'application/json': '{"abc": "dfg"}'
              }
          }],
          passthroughBehavior: PassthroughBehavior.NEVER,
          requestTemplates: {
              'application/json': '{ "statusCode": 200 }',
          },
      })

restApi.addMethod(
          "GET",
          mockIntegration,
          {
              methodResponses: [
                  { statusCode: '200' }
              ]
          });

What did you expect to happen?

I expected MockIntegration methods to work beside the LambdaIntegration methods, even with CORS enabled by default.

What actually happened?

Only the LambdaIntegration works, not the MockIntegration methods.
They work when testing through the API Gateway test option in the console, but not when hitting them with my browser, implying it's a problem with CORS/OPTIONS.

CDK CLI Version

2.4.0 (build 993f14d)

Framework Version

No response

Node.js Version

v16.13.1

OS

Ubuntu 21.10

Language

Typescript

Language Version

No response

Other information

A workaround is to set defaultCorsPreflightOptions to undefined for the resources with MockIntegration and manually add the method OPTIONS with passthroughBehavior: PassthroughBehavior.NEVER.

@Molaire Molaire added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jan 6, 2022
@github-actions github-actions bot added the @aws-cdk/aws-apigateway Related to Amazon API Gateway label Jan 6, 2022
@peterwoodworth
Copy link
Contributor

Hey @Molaire,

This doesn't seem to be an issue with the CDK, but rather CloudFormation or API Gateway. Do you find the same behavior when using the console?

@peterwoodworth peterwoodworth added needs-cfn This issue is waiting on changes to CloudFormation before it can be addressed. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. labels Jan 7, 2022
@github-actions
Copy link

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Jan 10, 2022
@ryparker ryparker added the p2 label Jan 10, 2022
@github-actions github-actions bot added closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Jan 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-apigateway Related to Amazon API Gateway bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. needs-cfn This issue is waiting on changes to CloudFormation before it can be addressed. needs-triage This issue or PR still needs to be triaged. p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

4 participants