javascriptamazon-dynamodb

DynamoDB BatchGetItem: Provided Key doesn't match?


So, I have been trying to retrieve a list of code from a DynamoDB table using batchGetItem

I tried to accomplish my task using the standard approach, which consists on pretty much using the basic code provided on AWS docs, as follows:

let AWS = require('aws-sdk');

AWS.config.update({
  "region": "us-west-2",
  "endpoint": "https://dynamodb.us-west-2.amazonaws.com",
  "accessKeyId": "my acess key here",
  "secretAccessKey": "my secret access key"
});

var dynamoClient = new AWS.DynamoDB.DocumentClient();    
var params = {
    "RequestItems": {
        "questions_and_answers": {
            "Keys": [
                {
                "codcategory": "10"
                }
            ]
        }
    }
}

var dynamoBatchGetPromise = dynamoClient.batchGetItem(params).promise();
dynamoBatchGetPromise.then(function (data) {
   console.log("data resp: " + JSON.stringify(data));
});

...and this is what I get as output:

"(node:3744) UnhandledPromiseRejectionWarning: ValidationException: The provided key element does not match the schema"

Well, since "codcategory" IS the actual Primary partition key of the table "questions_and_answers", and I want to retrieve all records from this table having codcategory = 10, I must ask;

What's wrong with my code?

Any help I'll appreciate. Thanks in advance.


Solution

  • Well, after digging a little more through the documentation, seems the problem was I had to provide both partition key AND hash key as paramenters, like that:

    Keys: [                
    {
    codcategory: {N:"10"},
    cod: {N:"2000"}
    }
    ]
    

    Well, that's it. Hope this mght help someone else in need at some point.