我应该如何修改 AWS DynamoDB 查询通过 AWS API 网关返回给我的响应?

How should I modify the response which is returned to me by AWS DynamoDB Query through AWS API Gateway?

我已经通过 AWS API 网关为 AWS DynamoDB 构建了一个查询 API。这是我在成功查询后得到的示例响应:

{
   "Count":2,
   "Items":[
      {
         "StoreID":{
            "S":"STR100"
         },
         "OrderID":{
            "S":"1019"
         },
         "Date":{
            "S":"22nd May"
         }
      },
      {
         "StoreID":{
            "S":"STR100"
         },
         "OrderID":{
            "S":"1020"
         },
         "Date":{
            "S":"22nd May"
         }
      }
   ],
   "ScannedCount":2
}

我想做的是,当响应到达 API 网关时(在它到达用户之前)我想修改它。我想对即将到来的回复进行以下更改 -

因此,修改后的响应应如下所示:

{
   "Count":2,
   "Items":[
      {
         "StoreID":"STR100",
         "OrderID":"1019",
         "Date":"22nd May"
      },
      {
         "StoreID":"STR100",
         "OrderID":"1020",
         "Date":"22nd May"
      }
   ]
}

希望您能理解我的问题 - 感谢您的帮助!
谢谢! :)

关注博文Using Amazon API Gateway as a proxy for DynamoDB

Navigate to Integration Response and expand the 200 response code by choosing the arrow on the left. In the 200 response, expand the Mapping Templates section. In Content-Type choose application/json then choose the pencil icon next to Output Passthrough.

对于您的示例,模板应如下所示:

#set($inputRoot = $input.path('$'))
{
    "Count": "$inputRoot.Count",
    "Items": [
        #foreach($elem in $inputRoot.Items) {
            "StoreID": "$elem.StoreID.S",
            "OrderID": "$elem.OrderID.S",
            "Date": "$elem.Date.S"
        }#if($foreach.hasNext),#end
        #end
    ]
}