API网关映射模板将JSON字符串转换为逗号分隔键=值对

发布于 2025-02-06 13:04:55 字数 817 浏览 5 评论 0原文

映射模板菜单在这里。

使用此查询字符串作为输入:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黯淡〆 2025-02-13 13:04:55

这并不是我想要的,但是,我能够通过构造字符串而不是dict来防止转换为KV,这样

{
    #set($data = "{
        ""userid"":""$input.params('userid')"",
        ""firstname"":""$input.params('firstname')"",
        ""lastname"":""$input.params('lastname')""
    }")
    "StreamName": "xyz",
    "Data": "$util.base64Encode($data)",
    "PartitionKey": "0"
}

我就会在这里离开此处,因为我确实必须与之搏斗一点。希望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:

{
    #set($data = "{
        ""userid"":""$input.params('userid')"",
        ""firstname"":""$input.params('firstname')"",
        ""lastname"":""$input.params('lastname')""
    }")
    "StreamName": "xyz",
    "Data": "$util.base64Encode($data)",
    "PartitionKey": "0"
}

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文