DynamoDB-关键元素与架构不匹配 [英] DynamoDB - Key element does not match the schema

查看:131
本文介绍了DynamoDB-关键元素与架构不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更新Dynamodb Table + Users +中的项目.我尝试了许多不同的方法,但始终收到相同的错误消息:

I'm trying to update an Item in my Dynamodb Table +Users+. I have tried many different ways but I always received the same error message:

提供的key元素与架构不匹配

The provided key element does not match the schema

创建Item以及查询(而不是更新)都可以.当我检查DynamoDB时,用户创建良好:

The creation of an Item works, as well as a query but not the update. When I check on DynamoDB the user is well created:

{
  "email": "test@email.com",
  "password": "123",
  "registration": 1460136902241,
  "verified": false
}

这是表格信息:

  • 表名:用户
  • 主分区键:电子邮件(字符串)
  • 主要排序键:注册(号码)
  • Table name: Users
  • Primary partition key: email (String)
  • Primary sort key: registration (Number)

以下是代码(从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.");
        });


    });

};

您是否知道我的代码中可能存在什么错误?

Do you have any idea of what could be wrong in my code?

推荐答案

您仅提供一半的主键.您的主键是分区键和范围键的组合.您需要在更新参数的Key属性中包含范围键.

You are only providing half of your primary key. Your primary key is a combination of the partition key and range key. You need to include the range key in your Key attribute in the update parameters.

这篇关于DynamoDB-关键元素与架构不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆