![](/img/trans.png)
[英]How should I test a DynamoDB PutItem API made with AWS API Gateway in Postman?
[英]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 網關時(在它到達用戶之前)我想修改它。 我想對即將到來的響應進行以下更改-
ScannedCount
值。 (保持Count
一)"S": "<value>"
:值應該直接出現,例如"StoreID": "STR100"
因此,修改后的響應應如下所示:
{
"Count":2,
"Items":[
{
"StoreID":"STR100",
"OrderID":"1019",
"Date":"22nd May"
},
{
"StoreID":"STR100",
"OrderID":"1020",
"Date":"22nd May"
}
]
}
我希望你能理解我的問題 - 任何幫助表示贊賞!
謝謝: :)
按照博客文章使用 Amazon API 網關作為 DynamoDB 的代理
導航到集成響應並通過選擇左側的箭頭展開 200 響應代碼。 在 200 響應中,展開映射模板部分。 在 Content-Type 中選擇 application/json 然后選擇 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
]
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.