2

I have an AWS Lambda function that I've set up and am attempting to hit from the front end. It works fine in browser, and returns the response I expect. When I try to hit it from localhost, I get a 403. I have tried to follow the steps outlined here and here (short of blowing away my entire API as some commenters mentioned), to no avail. I redeploy after all changes. After enabling CORS, I cease to get a 403, and instead get a 415. Unsure what to do next as there's nothing in the Cloudwatch logs.

Some more detail: I am using a Lambda:

enter image description here

I have a GET method ('Options' appeared after I enabled CORS):

enter image description here

Here's what happens when I click 'Enable CORS':

enter image description here

Because it's cut off in the screenshot, here is the complete list of headers: 'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'

Here's my Method Response: enter image description here

Here's how I call my lambda on the front end:

sendVerificationCode() {
    let data = {
      paramOne: x,
      paramTwo: 'string',
      paramThree: 'string'
    }

    return this.get('ajax').request('https://something.execute-api.us-east-1.amazonaws.com/beta/', {
      host: 'https://something.execute-api.us-east-1.amazonaws.com',
      method: 'GET',
      data: data
    }).then((response) => {
      console.log('response', response)
    });
  }

Here are the errors I'm getting. The first error, before I enable CORS: enter image description here

And after I enabled CORS: enter image description here

  • 1
    Possible duplicate of [API Gateway CORS: no 'Access-Control-Allow-Origin' header](https://stackoverflow.com/questions/35190615/api-gateway-cors-no-access-control-allow-origin-header) – varnit Jan 02 '19 at 19:24
  • Hii kira i think this question has been asked before you should use lambda proxy and send the cors headers manually like mentioned in the accepted answer – varnit Jan 02 '19 at 19:25
  • Hi There! Can you explain to me why I should use Lambda Proxy versus Lambda? There must be a way to do this with Lambda. –  Jan 02 '19 at 19:26
  • I'm saying this because i have tried a lot myself without lambda proxy and after a lot of efforts i failed and switched to lambda proxy, the same thing happened with other people as well – varnit Jan 02 '19 at 19:28

1 Answers1

0

CORS is a little finicky with API Gateway, have you tried it enabling it both at the root and on the method? That has previously worked for me. Also you can try downloading the javascript SDK for your api gateway project and using that to hit the route since it sets up all the correct settings for you.

  • Thanks for the tip! Option to disable on the root was disabled for some reason. –  Jan 03 '19 at 00:12