1
votes

Im working on an api gateway on aws services which performs BatchWriteItem operation to dynamodb. But I know there is a max 25 put items limit for one BatchWrite operation. Im new to vtl and Im not sure how to handle requests that have more than 25 put items. Im writing down my current body template.

Any hints or help will be appreciated. Thanks.

Body Mapping Template:

#set($inputRoot = $input.path('$'))
{
    "RequestItems": {
        "SensorDataTest": [
         #foreach($elem in $inputRoot.sensorMessages)
         { 
            "PutRequest": 
                {
                "Item": 
                    {
                    "GatewayID": 
                         {
                            "N": "$inputRoot.gatewayMessage.gatewayID"
                         },
                        "SensorID": {
                            "N": "$elem.sensorID"
                         },
                        "SensorName": {
                            "S": "$elem.sensorName"
                         },
                        "ApplicationID": {
                            "N":"$elem.applicationID" 
                        },
                        "NetworkID": {
                            "S":"$elem.networkID"
                        },
                        "DataMessageGUID": {
                            "S":"$elem.dataMessageGUID" 
                        },
                         "MessageDate": {
                            "S":"$elem.messageDate" 
                        },
                        "State": {
                             "N":"$elem.state" 
                        },
                        "RawData": {
                            "S": "$elem.rawData"
                        },
                        "DataType": {
                            "S": "$elem.dataType"
                        },
                        "DataValue": {
                            "S": "$elem.dataValue"
                        },
                        "PlotValues": {
                            "S": "$elem.plotValues"
                        },
                        "PlotLabels": {
                            "S": "$elem.plotLabels"
                        },
                        "SignalStrength": {
                            "N":"$elem.signalStrength"
                        },
                        "BatteryLevel": {
                            "N": "$elem.batteryLevel"
                        },
                        "PendingChange": {
                            "S": "$elem.pendingChange"
                        }
                    }
                }
        }#if($foreach.hasNext),#end
         #end
           
        ]
    },
    "ReturnConsumedCapacity": "TOTAL"
}
1

1 Answers

2
votes

No matter what you do in your velocity template, API Gateway will still only call the AWS integration once. By design, there is no way to do multiple backend integration calls to process a single API Gateway call. (Although we may consider adding this functionality in the future.)

If you need to put more than 25 items, the I recommend that you have your client loop through the items and make a separate call to your API for each 25 items.