Reputation: 365
I'm trying to get an item from a DynamoDB table, but this error "ValidationException: The provided key element does not match the schema" keeps happening. These are the parameters i created the table:
TableName : "Users-test",
KeySchema: [
{ AttributeName: "id", KeyType: "HASH"}, //Partition key
{ AttributeName: "email", KeyType: "RANGE" } //Sort key
],
AttributeDefinitions: [
{ AttributeName: "id", AttributeType: "S" },
{ AttributeName: "email", AttributeType: "S" }
]
And i'm trying to access the data like this:
const docClient = new AWS.DynamoDB.DocumentClient();
const params = {
TableName: 'Users-test',
Key:{
id: "someID",
email: "[email protected]"
}
};
docClient.get(params, function...
I know the record exists on the database and i can filter by id using the aws console, but actually using code i cannot get a record using the primary key, i tried to remove the "email" field from params variable, but it returned the same error.
Upvotes: 0
Views: 1862
Reputation: 41
You can this,
const config = {
region: 'eu-central-1'
};
const docClient = new AWS.DynamoDB.DocumentClient(config);
const params = {
TableName: 'Users-test',
Key:{
"someId",
"[email protected]"
}
};
docClient.get(params, function...
Also, you can make your function async
const docClient = new AWS.DynamoDB.DocumentClient(config);
const params = {
TableName: 'Users-test',
Key:{
"someId",
"[email protected]"
}
};
const result = await docClient.get(params).promise();
Upvotes: 1