PUT API包含路径参数和请求正文

时间:2016-02-02 06:13:17

标签: json api amazon-web-services amazon-dynamodb aws-api-gateway

我有一个PUT API网关端点,应该用它来更新DynamoDB条目。

该DynamoDB条目的id作为路径参数给出。

我有以下映射模板:

"application/json": {
    "id": "$input.params('id')",
    "title": "$input.json('$.title')"
}

按预期返回id。

如果我提交此请求正文

{
  "title": "Hello world" 
}

我收到错误Could not parse request body into json: Unexpected character (\'t\'

以下是我的AWS管理控制台的概述:

enter image description here

我错过了什么?

1 个答案:

答案 0 :(得分:1)

所以我找到了解决方案:

"title": "$input.json('$.title')"

应该是

"title": $input.json('$.title')(没有双引号)。

来源:http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html#input-variable-reference