Reputation: 89
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.
Upvotes: 0
Views: 620
Reputation: 1
i had the same problem, i used two keys in my table and only used one, but is necesary use both.
this is the code in golang
output, err := dynamoApi.DynamoDB.BatchGetItemWithContext(ctx, &dynamodb.BatchGetItemInput{
RequestItems: map[string]*dynamodb.KeysAndAttributes{
"felgt_qa_Billing": {
Keys: []map[string]*dynamodb.AttributeValue{
{
"uuid": &dynamodb.AttributeValue{
S: aws.String("CC649683-9034-49BA-A298-599AF2D6C8E2"),
},
"emissionDate": &dynamodb.AttributeValue{
S: aws.String("2024-05-30"),
},
},
{
"uuid": &dynamodb.AttributeValue{
S: aws.String("B4D9DA9E-208D-46DE-B146-1D8E611009A1"),
},
"emissionDate": &dynamodb.AttributeValue{
S: aws.String("2024-05-28"),
},
},
},
},
},
})
Upvotes: 0
Reputation: 89
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.
Upvotes: 1