API Gateway HTTP + Lambda integration not enabling CORS

1

I have an API Gateway with an HTTP API + route that utilizes a Lambda function integration.

From the AWS documentation, I see

If you configure CORS for an API, API Gateway automatically sends a response to preflight OPTIONS requests, even if there isn't an OPTIONS route configured for your API. For a CORS request, API Gateway adds the configured CORS headers to the response from an integration. If you configure CORS for an API, API Gateway ignores CORS headers returned from your backend integration.

However, I still get the errors:

Access to fetch at 'https://domain.execute-api.aws-region.amazonaws.com/dev/upload' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

From Cloudwatch, I can see the requests being sent to the API, but for some reason the header isn't properly configured. I do not understand this because I thought API Gateway should handle OPTIONS pre-flight requests for HTTP APIs. I cannot find out what I'm doing wrong. I'm not sure if it's because I'm not properly calling my API (link is https://domain.execute-api.aws-region.amazonaws.com/dev, stage is dev, route is /upload) or something else.

1 Risposta
1

Hello! In the example given, your URL would be https://domain.execute-api.aws-region.amazonaws.com/dev/upload. This article from AWS Support contains some very detailed debugging steps to try: https://aws.amazon.com/premiumsupport/knowledge-center/api-gateway-cors-errors/ . Hope it helps!

AWS
Clay_B
con risposta 2 anni fa

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande