0

I wrote a simple lambda function that takes a JSON dictionary I was able to access it successfuly using curl:

curl -X POST -H "Content-Type: application/json" -d '{
    "resource_id" : "zippo"
}' "<url of api gateway>"

But when I call it via javascript I get an error

var xhttp = new XMLHttpRequest();
xhttp.open("GET", "<url of api gateway>", true);
xhttp.send(`{"resource_id": "barium"}`);

Access to XMLHttpRequest at '' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Not sure if the issue is with the api gateway/lambda or my poor javascript skills.

Eyal Redler
  • 135
  • 7
  • 3
    Curl doesn't enforce CORS, but your browser does. The problem's in the server configuration, not the client. – jonrsharpe Oct 26 '22 at 16:03

0 Answers0