ArtK
ArtK

Reputation: 1185

AWS Lambda returns CORS header but browser fails API call

I have AWS Lambda function which is to be consumed by React app. When button is clicked, React uses axios.post() to pull data from the Lambda function. The function is configured with 1.0 response template. When testing in Postman, CORS headers - namely access-control-allow-origin is returned in response headers, as coded and expected.

enter image description here

However, when testing the app on local machine npm run dev the call results in CORS policy violation:

localhost/:1 Access to XMLHttpRequest at 'https://xxxxxxxx.execute-api.us-east-2.amazonaws.com/myFunction' from origin 'http://localhost:5173' 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

What am I missing here? Is it possible that the issue is with the fact that this is an open API and I'm not using any authentication?

Upvotes: -1

Views: 23

Answers (0)

Related Questions