API Gateway frontend for Lambda - CORS issue

0

I have a APIGateway setup in front of my Lambda function. I have done this twice before, and they both work. However this time I keep getting a CORS error in the browser dev tools view. I've run the 'test' function within the APIGateway and it works and shows that the Access-Control-Allow-Origin header is present... I'm not sure what this could be. I've compared this to the other two that work several times and I can't find any difference.

Interesting to note, if I have the .HTML on my local computer and open it in the browser, the page opens and the API loads with no problem! However, once I upload the HTML file to S3, and hit it via my URL, the page won't load the API and dev tools lists the error: ....has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

已提問 3 個月前檢視次數 152 次
1 個回答
1

Hello.

Have you configured API Gateway to return CORS headers in responses as described in the documentation below?
Also, is the "Access-Control-Allow-Origin" header configured to allow access from S3?
Does the Lambda function also include "Access-Control-Allow-Origin" in the response header?
https://repost.aws/knowledge-center/api-gateway-cors-errors

Whether or not to set the "Access-Control-Allow-Origin" header in the Lambda response depends on whether you are using "Lambda proxy integration" or not.
I recommend reading the following documentation for more information.
https://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-cors.html#apigateway-enable-cors-proxy

profile picture
專家
已回答 3 個月前

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

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

回答問題指南