请求正文正在覆盖 HTTP 方法?

Request body is overwriting the HTTP method?

Objective:获取调用AWS-API网关上的资源(路由)的方法。

我的进度: 我有一个具有 GET、PATCH、POST 方法的端点,在集成请求步骤中映射到模板。 PATCH 的模板如下所示:

"editJobsTemplate": {
     "application/json": {
     "method": "$context.httpMethod",
     "job": "$input.json('$.job')"
    }
 }

使用 this document 创建。

问题: 当 PATCH 正文为空时,我得到如下响应:

{
  "eventType": {
    "method": "PATCH",
    "job": ""
  }
}

但是当有一个以'job'作为键的对象在正文中发送时...

{
  "job":"some text value"
}

然后响应如下:

{
  "eventType": {
     "job": "some text value"
  }
}

编辑 1

This 是 API 网关资源面板中模板的屏幕截图。

我在 Postman 上测试得到 this result

编辑 2 This is to show the Content-Type header being set to application/json, as per the response from b.b3rn4rd, and this 显示我之后得到的回复。

调用端点时,请确保指定适当的 content-type header 。在您的情况下,它可能是 Content-Type: application/json,否则,将跳过请求映射并将请求按原样传递给 (lambda ?)。

此外,我已经发现 "job": "$input.json('$.job')"

的另一个潜在问题

应该是:

"job" : $util.escapeJavaScript($input.json('$.job')) 没有引号!