我的 lambda 可以使用 events["zip_code"]
在管理控制台中测试它并配置测试事件以实现这一点时。
如何配置我的 APIgateway 以传递 zip_code ?
我在几个小时内尝试了数百种不同的方法。这应该需要大约 30 秒才能弄清楚!
当前(精简)尝试:
我创建了一个 lambda。可引用event[zip_code"]
没问题。我创建了一个指向它的 API 网关,我可以调用它。然而,我每次尝试引用 lambda 中的查询字符串参数都失败了。
我已经尝试过:
event["zip_code"]
event["query_parameters"]["zip_code"]
event["queryStringParameters"]["zip_code"]
但他们都给出了零。
我已经尝试发布我的 lambda(可能需要),并且我已经尝试将我的 API 部署到特定阶段“DEV”,但似乎都没有帮助。
最佳答案
只要选中使用 Lambda 代理集成
,您就应该能够使用 event["queryStringParameters"]["zip_code"]
访问 Lambda 中的查询字符串参数。如果没有,那么您将需要设置自定义映射。在大多数用例中,代理集成是推荐的选项。
In Lambda proxy integration, when a client submits an API request, API Gateway passes to the integrated Lambda function the raw request as-is, except that the order of the request parameters is not preserved. This request data includes the request headers, query string parameters, URL path variables, payload, and API configuration data
非代理集成需要 custom mapping .
In Lambda non-proxy integration, in addition to the proxy integration setup steps, you also specify how the incoming request data is mapped to the integration request and how the resulting integration response data is mapped to the method response
关于amazon-web-services - 如何在 lambda 中引用查询字符串参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57938880/