我有一个链接到lambda函数的GET api网关调用(在传递有效的测试事件时,它在AWS UI中正确测试) . 我已经生成了一个javascript api(通过AWS UI),并通过它在ember js中进行调用 . 我已经用我的对象填充了所有三个参数(params,body,additionalParams),该对象定义了我想通过API调用传递的参数 . 这一切似乎都在起作用......除了API和lambda之间的数据传递 .
可悲的是,我无法从api请求中获取任何数据到我的lambda函数中 . 我尝试了以下不同的映射模板(我总是使用'Deploy API'):
#set($inputRoot = $input.path('$'))
{
"adultCount" : $inputRoot.adultCount,
"juniorCount" : $inputRoot.juniorCount,
"totalCost" : $inputRoot.totalCost,
"registeringUser" : "$inputRoot.registeringUser",
"registrations" : [
#foreach($elem in $inputRoot.registrations)
"$elem"
#if($foreach.hasNext),#end
#end
]
}
以及
{
"querystring" : "#foreach($key in $input.params().querystring.keySet())#if($foreach.index > 0)&#end$util.urlEncode($key)=$util.urlEncode($input.params().querystring.get($key))#end",
"body" : $input.json('$')
}
和
#set($keys = [])
#foreach($key in $input.params().querystring.keySet())
#set($success = $keys.add($key))
#end
#foreach($key in $input.params().headers.keySet())
#if(!$keys.contains($key))
#set($success = $keys.add($key))
#end
#end
#foreach($key in $input.params().path.keySet())
#if(!$keys.contains($key))
#set($success = $keys.add($key))
#end
#end
{
#foreach($key in $keys)
"$key": "$util.escapeJavaScript($input.params($key))"#if($foreach.hasNext),#end
#end
}
为什么我的数据不通过API流入我的函数?建议?
1 回答
看起来你至少与你的第一个映射模板很接近 . 我修改了一点,并能够使这个工作:
在模板的某些部分,它看起来像是在试图解析请求的主体 - 而GET可以有一个主体,通常服务器应该忽略它 . 因此,如果您在GET上发送数据,则应该在查询字符串, Headers 和/或cookie中 . 当查询字符串的格式如下时,上面的模板有效:
?adultCount=3&juniorCount=4&totalCost=5®isteringUser=bob®istrations=99,88,66,55
.