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.

已提問 2 年前檢視次數 4345 次
1 個回答
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
已回答 2 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南