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

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.

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠