2017-06-22 32 views
1

我正在通过AWS API网关公开我的DDB。我有它的工作,但是当我通过我的“PUT”时,它要求我将我的DDB中的每个字段都包含在正文请求中。有些客户可能只想发布我的DDB中10个字段中的5个字段。这将作为POST还是PATCH来完成?如果是这样,我的映射模板是什么样的?暴露DynamoDB的API网关(需要复杂的映射模板或Lamdba函数?)

第二:我想添加一个自动生成的order_number到DDB中的每个条目。所以现在每个PUT或POST都会有一个唯一的order_number。所以我的主键是一个变量,次键是一个客户sku号码,反之亦然。

感谢您的帮助。

回答

0

Body Template:我仍然需要它为每个新条目自动生成“order_number” 。

#set($inputSep = $input.path('$')) 
#set($thisLoop = 
'{"CustomerNm":"1","ShipDate":"2","Shipping":"3","commentId":"4"}') 
#set($myPlaces = $util.parseJson($thisLoop)) 
#set($allKeys = '') 
#set($myVals = '"') 
{ 
"TableName": "BRPI", 
"Key": { 
    "CustomerID": { 
     "S": "$input.path('$.CustomerID')" 
    } 
}, 
#foreach($type in $inputSep.keySet()) 
#if($type == "CustomerID") 
#else 
    #set($thisPlace = $myPlaces.get($type)) 
    #set($params = $inputSep.get($type)) 
    #set($thisKey = "$type" + " = :val" + "$thisPlace") 
    #set($thisPath = "$params") 
    #if($foreach.hasNext) 
     #set($myComma = ",") 
     #set($myReturn = '"') 
    #else 
     #set($myComma = "") 
     #set($myReturn = "") 
    #end 
    #set($allKeys = "$allKeys" + "$thisKey" + "$myComma") 
    #set($myVals = "$myVals" + ":val" + "$thisPlace" + '": {"S": "' + 
"$thisPath" + '"}' + "$myComma" + "$myReturn") 
#end 
#end 
"UpdateExpression": "SET $allKeys", 
"ExpressionAttributeValues": { 
    $myVals 
}, 
"ReturnValues":"UPDATED_NEW" 
}