2
votes

I want to call BatchGetItem to fetch multiple documents from simple table in DynamoDB using API Gateway json mapping template inside integration request. Below template works for me when using Query action to get single item:

    {
    "TableName": "Test",
    "KeyConditionExpression": "ItemId = :i",
    "ExpressionAttributeValues": {
        ":i": {
            "N": "7"
        }
    }

When I change action to BatchGetItem and use following template I always get "__type": "com.amazon.coral.service#SerializationException" with status 400.

Endpoint request body after transformations in log looks correct and is exactly the template below. I also tested same request with nodejs sdk and it works perfect.

{
    RequestItems: {
        "Test": {
            Keys: [
                    { "ItemId": 7 }
            ],
            ProjectionExpression: "ItemId,Status,EventTime"
        }
    }
}

also tried this:

{
    RequestItems: {
        "Test": {
            Keys: [
                    { "ItemId": {"N":"7" }}
            ],
            ProjectionExpression: "ItemId,Status,EventTime"
        }
    }
}
1
FWIW (in general) here is a recent new tutorial that seems to do everything you need (with 1 small exception that it is using regular GetItem, instead BatchGetItem as in this Question), and has more details/screenshots than I've seen in others: medium.com/@likhita507/… - cellepo

1 Answers

2
votes

I managed to solve this by wrapping all properties and values as strings and setting key value type

{
    "RequestItems": {
        "Test": {
            "Keys": [
                    { "ItemId": {"N":"7" }}
            ],
            "ProjectionExpression": "ItemId,Status,EventTime"
        }
    }
}