2

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/… Commented May 8, 2020 at 23:38

1 Answer 1

2

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"
        }
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Indeed, your original request was not valid JSON - strings need to be quoted. SerializationException means the input was not valid JSON.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.