0

I have been struggling with setting up AWS API Gateway to pass Query string parameters to my Lambda function.

If I set to API to use Lambda proxy integration, I get a CORS error at the Web client

[index.html:1 Access to XMLHttpRequest at 'https://g2kza1o79f.execute-api.eu-west-2.amazonaws.com/prod/gettest8' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.]

( - even when I have set the API with CORS enabled.

If I set the API to not use Lambda proxy integration, and CORS enabled, the API call works (no CORS error), but the event object received in my Lambda function is empty( hence no query string parameters). In both cases I am using the GET method. I can see in the Method Response Header the Access-Control-Allow-Origin option is present, but cannot access the Integration Response

Question: How can I set-up my API to pass query string parameters through to my Lambda function without getting the CORS error? I will also be wanting to set up APIs for POST requests to other Lambda functions.

Traycho Ivanov
  • 2,887
  • 14
  • 24
pyBristow
  • 9
  • 1
  • Just for clarity. I was not clear in the Lambda Proxy integration set up. I have checked the Method Response and Integration Response areas for the OPTIONS Method, and Access-control-allow/origin/methods are all present. Could it me that the CORS error message is caused by something else? – pyBristow Aug 19 '20 at 09:57
  • Does this answer brings any sense ? https://stackoverflow.com/questions/31329958/how-to-pass-a-querystring-or-route-parameter-to-aws-lambda-from-amazon-api-gatew – Traycho Ivanov Aug 19 '20 at 11:03
  • ThanksTraycho Ivanov - your suggested link gave more information about manually setting up QueryString mappings - which I have tried, but still struggled with getting CORS working as well. There may be some kind of hybrid answer. – pyBristow Aug 19 '20 at 12:48
  • Does this answer your question? [API Gateway CORS: no 'Access-Control-Allow-Origin' header](https://stackoverflow.com/questions/35190615/api-gateway-cors-no-access-control-allow-origin-header) – Traycho Ivanov Aug 20 '20 at 19:12

1 Answers1

0

I believe it is related to First Enable CORS Then Deploy API.

A good thread could be found here. API Gateway CORS: no 'Access-Control-Allow-Origin' header

Traycho Ivanov
  • 2,887
  • 14
  • 24
  • Thank again. After reading through the link you provided and applying a change I seem to have solved the problem. – pyBristow Aug 19 '20 at 15:42
  • The fix(at least for me) was to add the appropriate header information ( Access-Allow-Origin etc) in the return response in my Lambda function. Not very need , but if it works I can live with it. I still have to set up POST request APIs but hoping the fix still works for them – pyBristow Aug 19 '20 at 15:44