且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

ValidationException:提供的键元素与架构不匹配

更新时间:2022-12-04 15:25:55

为进一步说明这种情况的发生原因,您最初使用的是

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'
};

注意,包裹"user_id"值的"S"已从上述代码中删除.稍后,您通过使用"aws-sdk"切换回低级javascript sdk,因此带有"S"标签的代码最终可以正常工作.

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.