API Gateway blocking response from Lambda via CORS despite CORS headers in response.

0

When I attempt to POST to my REST API deployed to API Gateway, my Lambda does not return a proper response. Instead, it returns:

Access to fetch at 'https://dev.api.no-name-games.com/pay' from origin 'http://localhost:8080' has been blocked by CORS policy: 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.

I read somewhere that if your API is a REST API with a Lambda integration, you can't set CORS via the console, so I set it in the Lambda itself:

return events.APIGatewayProxyResponse{
	StatusCode: 200,
	Headers: map[string]string{
		"Access-Control-Allow-Origin": "*",
	},
	Body: data.ClientSecret,
}, err

However, when I look at my request/response, I do not see those headers: Enter image description here

已提問 7 個月前檢視次數 366 次
1 個回答
0

You have to also enable CORS on API Gateway itself as well AND manage it on lambda too.

On API Gateway, set allowed origins to * and keep your lambda code the same.

Later on when you want to deploy, leave API Gateway as *, but then specify your domain within the lambda function.

Let me know if this helps

已回答 7 個月前
  • How/where do I set it in API Gateway? The Enable CORS option does not seem to work.

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

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

回答問題指南