I am using AWS.DynamoDB.DocumentClient in a nodejs program to fetch items from multiple Dynamodb tables. To make code simple, I choose to use BatchGetItem/BatchGet method.
The challenge is I need to fetch items based on a Global Secondary Index, e.g. name+age, rather than the initial primary key generated when creating the table. I went through BatchGetItem/BatchGet but not see any parameters of using Global Secondary Index.
I ran some testing with the following code
var params = { RequestItems: { 'Table-1': { Keys: [ { name: 'abc', age: 18, }, ] } } }; var docClient = new AWS.DynamoDB.DocumentClient(); docClient.batchGet(params, function(err, data) { if (err) console.log(err); else console.log(data); });
And got following error.
> ValidationException: The provided key element does not match the
> schema
Does it mean BatchGetItem/BatchGet can't use Global Secondary Index, and I have to read from tables one by one?