API网关映射模板将JSON字符串转换为逗号分隔键=值对
映射模板菜单在这里。
使用此查询字符串作为输入:
userId = foo& firstName = bar& lastName = bat
我需要将数据发布到jinesis中,因此:
{
"userid":"foo",
"firstname":"bar",
"lastname":"bat"
}
但是,根据消费的lambda,它到达了kinesis,它到达了kinesis,它到达了转换为comma parterpareated键=值=值=值对,因此:
userId = foo,firstName = bar,lastname = bat
Google找到了一些旧的论坛帖子,概述了相同的问题,但没有解决方案。
这是我正在使用的映射模板:
{
#set($data = {
"userid":"$input.params('userid')",
"firstname":"$input.params('firstname')",
"lastname":"$input.params('lastname')"
})
"StreamName": "xyz",
"Data": "$util.base64Encode($data)",
"PartitionKey": "0"
}
似乎映射模板将$数据命令转换为逗号分隔的key = value对的列表。也许我应该构建一个JSON字符串而不是dict,但是我认为,这种行为必须是可配置的。如何指示系统构建JSON而不是KV?
Mapping template noob here.
Using this query string as input:
userid=foo&firstname=bar&lastname=bat
I need to POST data to Kinesis as JSON, thus:
{
"userid":"foo",
"firstname":"bar",
"lastname":"bat"
}
However, according to a consuming Lambda, it arrives at Kinesis translated into comma-separated key=value pairs, thus:
userid=foo, firstname=bar, lastname=bat
Google found some old forum posts outlining the same problem, but no solution.
This is the mapping template I'm using:
{
#set($data = {
"userid":"$input.params('userid')",
"firstname":"$input.params('firstname')",
"lastname":"$input.params('lastname')"
})
"StreamName": "xyz",
"Data": "$util.base64Encode($data)",
"PartitionKey": "0"
}
It seems the mapping template is converting the $data dict into a comma-separated list of key=value pairs. Perhaps I should construct a JSON string rather than a dict, but, this behavior must be configurable, I'd think. How to instruct the system to construct JSON rather than KV?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这并不是我想要的,但是,我能够通过构造字符串而不是dict来防止转换为KV,这样
我就会在这里离开此处,因为我确实必须与之搏斗一点。希望Google将来将某人发送到这里时,这会有所帮助。
This wasn't exactly what I was looking for, but, I'm able to prevent the conversion to KV by constructing a string rather than a dict, as so:
I'm gonna leave this here since I did have to wrestle with it for a bit. Hopefully when Google sends someone here in future it'll be helpful.