AWS API Gateway: Unable to enable CORS for some resources defined in OpenAPI Specification v.3

0

I am using OpenAPI Specification 3 with terraform to create resources and methods in my API Gateway. Surprisingly for some resources CORS is not getting enabled. I am not seeing any pattern for which it is failing. For enablement of CORS, I am using the standard way of using the OPTIONS method provided by Amazon documentation. Here is the code for the OPTIONS method:

options: summary: CORS support description: Enable CORS by returning correct headers tags: - CORS responses: 200: description: Default response for CORS method headers: Access-Control-Allow-Origin: schema: type: string Access-Control-Allow-Methods: schema: type: string Access-Control-Allow-Headers: schema: type: string content: {} x-amazon-apigateway-integration: type: mock requestTemplates: application/json: { "statusCode" : 200 } responses: default: statusCode: 200 responseParameters: method.response.header.Access-Control-Allow-Headers: "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'" method.response.header.Access-Control-Allow-Methods: "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'" method.response.header.Access-Control-Allow-Origin: "'*'" responseTemplates: application/json: {}

On investigating and troubleshooting through the API Gateway Console, I observed that in Integration Request, request template this line is not getting implemented: { "statusCode" : 200 } because of which I am getting the following error on testing Options method from API Gateway Console: *Thu Jun 22 02:23:16 UTC 2023 : Execution failed due to configuration error: Unable to parse statusCode. It should be an integer that is defined in the request template. Thu Jun 22 02:23:16 UTC 2023 : Method completed with status: 500 This results in a CORS issue when a GET method is called attached with the same resource. I am not sure why it is failing to implement because same OPTIONS method is implemented for other resources and they are working fine.

  • Could you provide screenshot of the integration requests and responses?

  • Could you provide screenshot of the integration requests and responses?

Keine Antworten

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen