我正在尝试更新DynamoDB表+ Users +中的一项。我尝试了许多不同的方法,但始终收到相同的错误消息:
提供的关键元素与模式不匹配
创建项目以及查询都可以,但更新则不行。当我在DynamoDB上检查时,用户已经创建成功:
{
"email": "test@email.com",
"password": "123",
"registration": 1460136902241,
"verified": false
}
这是表格信息:
- 表名: Users
- 主分区键: email (字符串)
- 主排序键: registration (数字)
以下是代码(从 Lambda 调用):
exports.handler = function(event, context)
{
var AWS = require("aws-sdk");
var docClient = new AWS.DynamoDB.DocumentClient();
var params = {
TableName: "Users",
Item:{
email: "test@email.com",
password: "123",
verified: false,
registration: (new Date()).getTime(),
}
};
// Create the user.
docClient.put(params, function(err, data)
{
if (err)
{
context.fail("Put failed...");
return;
}
var params = {
TableName: "Users",
Key: { email : "test@email.com" },
AttributeUpdates: {
verified: {
Action: "PUT",
Value: true
}
}
};
// Update the user.
docClient.update(params, function(err, data)
{
if (err)
{
console.log(JSON.stringify(err));
context.fail(JSON.stringify(err));
return;
}
context.succeed("User successfully updated.");
});
});
};
你有没有想过我的代码可能出了什么问题?