CORS error when POSTing to API Gateway endpoint

Viewed 25

I am setting up an API gateway to trigger a lambda function. I am able to successfully test the API trigger in the AWS environment, however when I try to hit the endpoint locally I receive this error:

... 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.

The lambda function I am trying to hit has the following response:

    return {
        'statusCode': 200,
         'headers': {
            "Access-Control-Allow-Origin" : "*"
            "Access-Control-Allow-Credentials" : true
         },
    }

My fetch request looks like this:

fetch("url here", 
{
  method: "POST",
  headers: {
    "Content-Type": "application/json",
  },
  body: { name: "hello", contact: "Tim", phone: "555" },
}

I am not really sure what is going on. Any help would be appreciated.

0 Answers
Related