RyeGuy
RyeGuy

Reputation: 4483

AWS Api Gateway 403 error - CORS enabled from all origins

I have created a lambda function which is to be accessed via an API Gateway. However whenever a post request is made I get the following error

enter image description here

When I navigate to was console and look at API Gateway I have

enter image description here

Finally my code (Angular2) does add the appropriate headers to the request by:

var headers = new HttpHeaders();
headers.append('Content-Type', 'application/json');

this.http.post('https://execute-api.us-east-1.amazonaws.com/prod/LambdaFunction', this.email, { headers: headers })
  .subscribe(data => console.log(data),
    err => console.log(err));

Any idea how to fix this?

Upvotes: 2

Views: 7673

Answers (3)

Dileep
Dileep

Reputation: 346

Try this first

  1. Enable CORS options to add "Access-Control-Allow-Origin": "*" header to your response. Dont add authonticater to Options resources.
  2. Add plugin to web browser to overrride cors settings of browser. (just for test on browser. you dont need this while app is running on file system)
  3. check your request url/endpoint to be sure is ok.

if this is not resolve from above use the below options as well. In my case if resolve by below steps.

  1. Add Access-Control-Allow-Origin: * in Default 4XX response. (Refer below Picture.)
  2. Redeploy the API.

    enter image description here

Upvotes: -2

mylnz
mylnz

Reputation: 424

I was getting same error and I fixed the issue following path:

  • Enable CORS options to add "Access-Control-Allow-Origin": "*" header to your response. Dont add authonticater to Options resources.
  • Add plugin to web browser to overrride cors settings of browser. (just for test on browser. you dont need this while app is running on file system)
  • check your request url/endpoint to be sure is ok.

Upvotes: 1

Kannaiyan
Kannaiyan

Reputation: 13025

Looks like you are beating the wrong bush.

You cannot enable CORS on a 403 since that is sent by APIGateway. The issue is you are trying to access a URL that is not accessible by APIGateway.

If your URL is correct and POST worked, you will still receive 200 OK on a CORS call, but you will not be able to access the content received. (That is browser standard to avoid CORS call without valid permission on the return headers)

Upvotes: 6

Related Questions