AWS LAMBDA:访问不同内容类型的请求 headers 和 body?
AWS LAMBDA: Accessing request headers and body of different content types?
我正在尝试使用 aws api 网关部署 lambda 函数。通过关注此博客,我能够使用 Content-Type:application/json 成功部署和测试 POST 和 GET 方法:http://kennbrodhagen.net/2015/12/06/how-to-create-a-request-object-for-your-lambda-event-from-api-gateway/
我希望我的同一个 lambda 函数也能处理 content-type 的请求:text/plain
、x-www-form-urlencoded
。
集成模板的问题是我们必须事先定义 content-type。因此,如果我制作了 Content-type: text/plain
的集成模板,当 text/plain
的 api 请求被发送到 url 时,我该如何调用该集成模板。
如何根据 api 请求的 Content-Type 调用不同的集成模板?
有什么建议吗?
谢谢。
我不知道我是否理解你的问题。
根据我的理解,如果您要传递任何 header 信息或查询字符串参数并且内容类型是 text/plain,您可以像这样映射模板
{
"prod_Id" : "$input.params('prod_Id')"
}
其中产品 ID 可以是 header 或查询字符串参数。
你可以在'how to pass query string section
我的blog中找到它
我正在尝试使用 aws api 网关部署 lambda 函数。通过关注此博客,我能够使用 Content-Type:application/json 成功部署和测试 POST 和 GET 方法:http://kennbrodhagen.net/2015/12/06/how-to-create-a-request-object-for-your-lambda-event-from-api-gateway/
我希望我的同一个 lambda 函数也能处理 content-type 的请求:text/plain
、x-www-form-urlencoded
。
集成模板的问题是我们必须事先定义 content-type。因此,如果我制作了 Content-type: text/plain
的集成模板,当 text/plain
的 api 请求被发送到 url 时,我该如何调用该集成模板。
如何根据 api 请求的 Content-Type 调用不同的集成模板?
有什么建议吗?
谢谢。
我不知道我是否理解你的问题。
根据我的理解,如果您要传递任何 header 信息或查询字符串参数并且内容类型是 text/plain,您可以像这样映射模板
{
"prod_Id" : "$input.params('prod_Id')"
}
其中产品 ID 可以是 header 或查询字符串参数。
你可以在'how to pass query string section