I've setup an AWS lambda function which returns some data and then an API gateway a POST method , and then setup API gateway pointing to it (no authorization).
I want to allow access from any origin. I believe I've setup my CORS headers and api gateway appropriately, but I'm still getting a preflight response error.
I've added the headers to the lambda function:
exports.handler = async (event) => {
return {
statusCode: 200,
headers: {
"Access-Control-Allow-Headers": "*",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "*",
"Access-Control-Allow-Credentials": true,
'Content-Type': 'application/json'
},
body: JSON.stringify({})
}
};
In API gateway, I've enabled CORS which created the OPTIONS method for the preflight response using MOCK integration type.
I've confirmed my POST request works in postman.
However, on client side I get the preflight request error:
Access to fetch at '[API Gateway URL]' from origin 'MY WEBSITE' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
Checking the network log, the OPTIONS endpoint is returning HTTP 500 error and I cant figure out what is wrong with my configuration in API gateway. The endpoint returns 200 when I test it in API gateway. Am I missing some configuration step to configure CORS?




