如何将查询字符串或路由参数从 Amazon API Gateway 传递给 AWS Lambda [英] How to pass a querystring or route parameter to AWS Lambda from Amazon API Gateway

查看:34
本文介绍了如何将查询字符串或路由参数从 Amazon API Gateway 传递给 AWS Lambda的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如如果我们想使用

GET/user?name=bob

GET/user/bob

您将如何将这两个示例作为参数传递给 Lambda 函数?

How would you pass both of these examples as a parameter to the Lambda function?

我在文档中看到了有关设置映射自"的内容,但在 API Gateway 控制台中找不到该设置.

I saw something about setting a "mapped from" in the documentation, but I can't find that setting in the API Gateway console.

  • method.request.path.parameter-name 用于在方法请求页面中定义的名为 parameter-name 的路径参数.
  • method.request.querystring.parameter-name 用于在方法请求页面中定义的名为 parameter-name 的查询字符串参数.
  • method.request.path.parameter-name for a path parameter named parameter-name as defined in the Method Request page.
  • method.request.querystring.parameter-name for a query string parameter named parameter-name as defined in the Method Request page.

即使我定义了查询字符串,我也没有看到这些选项中的任何一个.

I don't see either of these options even though I defined a query string.

推荐答案

自 2017 年 9 月起,您不再需要配置映射来访问请求正文.

As of September 2017, you no longer have to configure mappings to access the request body.

您需要做的就是在资源下的集成请求下选中使用 Lambda 代理集成".

All you need to do is check, "Use Lambda Proxy integration", under Integration Request, under the resource.

然后您就可以像这样访问查询参数、路径参数和标题

You'll then be able to access query parameters, path parameters and headers like so

event['pathParameters']['param1']
event["queryStringParameters"]['queryparam1']
event['requestContext']['identity']['userAgent']
event['requestContext']['identity']['sourceIP']

这篇关于如何将查询字符串或路由参数从 Amazon API Gateway 传递给 AWS Lambda的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆