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?