When setting up CORS in API Gateway with CDK, the preflight request results in 500 InternalServerErrorException

0

We set up CORS according to https://docs.aws.amazon.com/cdk/api/v2/python/aws_cdk.aws_apigateway/Cors.html

apigateway.RestApi(self, "api",
    default_cors_preflight_options=apigateway.CorsOptions(
        allow_origins=apigateway.Cors.ALL_ORIGINS,
        allow_methods=apigateway.Cors.ALL_METHODS
    )
)

After deployment, CDK automatically creates OPTIONS method to all endpoints.

When making a preflight request with curl -X OPTIONS https://hostname/path/to/endpoint we receive following response

< HTTP/2 500 
< date: xxxxxxxxxxxxx
< content-type: application/json
< content-length: 36
< x-amzn-requestid: xxxxxxxxxxxxxx
< x-amzn-errortype: InternalServerErrorException
< x-amz-apigw-id: xxxxxxxxxxxxxxxxxxx
< x-amzn-trace-id: xxxxxxxxxxxxxxxxxxxxxxxx

In CloudWatch, we see following log:

HTTP Method: OPTIONS, Resource Path: /path/to/endpoint                                                                                 
Execution failed due to configuration error: Unable to transform request                                                                
Method completed with status: 500

What is the cause of the problem and how can we fix it?

No hay respuestas

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas