DynamoDB - the key element does not match the scheme

I am trying to update an item in a Dynamodb + Users + table. I tried many different ways, but always got the same error message:

Key element provided does not match schema

Creating an item works as well as querying, but not updating. When I check DynamoDB, the user is well created:

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

Here is the table information :

  • Table Name : Users
  • Section primary key : email (string)
  • Main sort key : registration (number)

Here is the code (called from 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 what might be wrong in my code?

+6
source share
1 answer

You provide half the primary key. A primary key is a combination of a partition key and a range key. You need to include the range key in your Key attribute in the update options.

+15
source

All Articles