amazon-web-services - 如何在 lambda 中引用查询字符串参数

标签 amazon-web-services aws-lambda aws-api-gateway

我的 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 中的查询字符串参数。如果没有,那么您将需要设置自定义映射。在大多数用例中,代理集成是推荐的选项。

enter image description here

See docs

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/

相关文章:

amazon-web-services - 将 s3 上的多个 zip 文件合并为较少的 zip 文件

node.js - 无服务器框架 : how to deploy with CloudFormation?

amazon-web-services - 如何在 CloudFormation 模板中使用 SSM StringList 中的值?

python - 如何以 json 格式将 pandas 数据帧 to_json() 写入 s3

amazon-web-services - 如何在 AWS Lambda 中验证 Cognito 访问 token 以允许网关 API 调用?

amazon-web-services - 一次性创建多个卷 aws cloudformation

node.js - AWS Cognito 用户池的事件触发器对象

node.js - 解析请求体禁止请求签名验证

amazon-web-services - AWS API Gateway 无法打开

aws-api-gateway - API 网关 HTTP 代理与无服务器离线集成(不是 Lambda 代理)