【问题标题】:API Gateway exposing DynamoDB (Complex mapping template or Lambda Function needed?)公开 DynamoDB 的 API 网关(需要复杂的映射模板或 Lambda 函数?)
【发布时间】:2017-06-22 13:47:53
【问题描述】:

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

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

感谢您的帮助。

【问题讨论】:

    标签: api amazon-web-services gateway


    【解决方案1】:

    正文模板:我仍然需要它来生成“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"
    }
    

    【讨论】:

      猜你喜欢
      • 2017-06-24
      • 1970-01-01
      • 2018-06-04
      • 2019-07-11
      • 1970-01-01
      • 2020-03-31
      • 1970-01-01
      • 1970-01-01
      • 2020-10-01
      相关资源
      最近更新 更多