如何查询字符串或路由参数从亚马逊API网关传递到AWS LAMBDA [英] How to pass a querystring or route parameter to AWS Lambda from Amazon API Gateway

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

问题描述

例如,如果我们要使用

GET /用户?名=鲍勃

GET /用户/鲍勃·

你将如何通过这两个例子作为参数传递给lambda函数?

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

我看到的东西有关设置的文档中的从映射,但我找不到API网关控制台设置。

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名名为路径参数参数名称中所定义的方法请求的页面。
  • method.request.querystring.parameter名名为查询字符串参数参数名称中定义该方法请求的页面。
  • 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.

推荐答案

要得到这个工作的步骤是:

The steps to get this working are:

  1. 转到资源 - >集成请求
  2. 点击加号或旁边的编辑图标模板下拉(奇怪的,我知道,因为模板字段已经打开,并且这里的按钮看起来呈灰色)
  3. 下明确键入应用程序/ JSON 中,即使它显示了一个默认的(如果你不这样做就不会保存,不会给你的内容类型字段错误消息)
  4. 把这个输入映射 {名:$ input.params('名')}

  1. go to Resources -> Integration Request
  2. click on the plus or edit icon next to templates dropdown (odd I know since the template field is already open and the button here looks greyed out)
  3. Explicitly type application/json in the content-type field even though it shows a default (if you don't do this it will not save and will not give you an error message)
  4. put this in the input mapping { "name": "$input.params('name')" }

点击旁边的下拉列表中的模板(我假定这就是最终将其保存)复选框

click on the check box next to the templates dropdown (I'm assuming this is what finally saves it)

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

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