简体   繁体   English

AWS API 网关:CORS 和空事件 Object

[英]AWS API Gateway : CORS and Empty Event Object

I have been struggling with setting up AWS API Gateway to pass Query string parameters to my Lambda function.我一直在努力设置 AWS API 网关以将查询字符串参数传递给我的 Lambda function。

If I set to API to use Lambda proxy integration, I get a CORS error at the Web client如果我设置为 API 以使用 Lambda 代理集成,我会在 Web 客户端收到 CORS 错误

[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. ( - 即使我设置了 API 并启用了 CORS。

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). 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.在这两种情况下,我都使用 GET 方法。 I can see in the Method Response Header the Access-Control-Allow-Origin option is present, but cannot access the Integration Response我可以在方法响应 Header 中看到存在 Access-Control-Allow-Origin 选项,但无法访问集成响应

Question : How can I set-up my API to pass query string parameters through to my Lambda function without getting the CORS error?问题:如何设置我的 API 以将查询字符串参数传递到我的 Lambda function 而不会出现 CORS 错误? I will also be wanting to set up APIs for POST requests to other Lambda functions.我还想为其他 Lambda 函数的 POST 请求设置 API。

I believe it is related to First Enable CORS Then Deploy API.我相信它与 First Enable CORS Then Deploy API 有关。

A good thread could be found here.可以在这里找到一个好的线程。 API Gateway CORS: no 'Access-Control-Allow-Origin' header API 网关 CORS:没有“访问控制允许来源”header

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM