ValidationException:提供的关键元素与架构不匹配 [英] ValidationException: The provided key element does not match the schema
问题描述
I created a table 'user_info' in DynamoDB with one primary hash key 'user_id'(String), no range key. Then I created 2 AWS lambda functions to insert and query the items. I can insert items into the table, but when I query the table, it returns:
ValidationException: The provided key element does not match the schema.
My query function :
var params = {
Key: {
user_id:{
S: "usr1@s.com"
}
},
TableName: 'user_info',
ProjectionExpression: 'password'
};
dynamodb.getItem(params,
function(err, data) {
if (err) {
console.log("get item err." + err);
context.done('error','getting item from dynamodb failed: '+err);
}
else {
console.log('great success: '+JSON.stringify(data, null, ' '));
context.succeed('created user ' + event.user_id + ' successfully.');
}
});
I keep getting this exception:
ValidationException: The provided key element does not match the schema
Since
1) I have only one hash primary key.
2)user_id is defined as String. I really don't know why there is a mismatch error.
To clarify further on why this is happening, you were originally using the DynamoDB Document Client, which eliminates to need to explicitly label your attributes as "String" (S) or "Number" (N) etc. Therefore, your original code would have worked with
var doc = require('dynamodb-doc');
var dynamodb = new doc.DynamoDB();
var params = {
Key: {
user_id: "usr1@s.com"
},
TableName: 'user_info',
ProjectionExpression: 'password'
};
Note the "S" wrapping the value of "user_id" is removed from the above code. Later on, you switched back to the low-level javascript sdk by using 'aws-sdk', so your code with "S" label ended up working.
这篇关于ValidationException:提供的关键元素与架构不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!