Dynamoose: AWS Error: One of the required keys was not given a value.

Created on 24 Feb 2017  Â·  10Comments  Â·  Source: dynamoose/dynamoose

I have a weird error regarding getting data with dynamoose.
What I do is using objectmodel to define/validate my models. I can put/save elements via dynamoose to dynamodb but when trying to get an object an error occurs.

var db = require("dynamoose");

var get = function(table, object) {
  return db.model(table, object.constructor.definition).get(object.id);
};

var put = function(table, object) {
  var model = db.model(table, object.constructor.definition);
  var newObj = new model(object);
  return newObj.save();
};

So I have a test file to first put data to dynamodb and after that get that data. I can see the data is written to dynamodb with the put-function but when I try to get it with the get-function the error is the following, even if the definition file is exactly the same.

{
  "message": "One of the required keys was not given a value",
  "code": "ValidationException",
  "time": "2017-02-24T21:42:10.423Z",
  "requestId": "5f10ff0c-e889-41d1-8992-8e0480bd27fb",
  "statusCode": 400,
  "retryable": false,
  "retryDelay": 0
}

Any idea on this?

Current definition file of objectmodel (object.constructor.definition):

{
 address: 
   { company: [ [Function: String] ],
     name: [Function: String],
     street: [Function: String],
     zip: [Function: String],
     city: [Function: String],
     country: [Function: String] },
  id: [Function: String]
}

Definition File for DynamoDB which I use to create the table. id is my key at the moment:

{
  "TableName": "customers",
  "KeySchema": [{
    "AttributeName": "id",
    "KeyType": "HASH"
  }],
  "AttributeDefinitions": [{
    "AttributeName": "id",
    "AttributeType": "S"
  }],
  "ProvisionedThroughput": {
    "ReadCapacityUnits": 5,
    "WriteCapacityUnits": 5
  }
}

Picture of Local Test Environment:
screen shot 2017-02-25 at 12 33 03
screen shot 2017-02-25 at 12 33 09
hashKey equals the id which I pass in get-function via object.id and ObjectJSON is the Data I wrote to db.

Most helpful comment

Hi

I have the same issue with the following configuration

const CompanySchema = dynamoose.Schema({
  id: {
    type: String,
    hashKey: true,
  },
  companyName: {
    type: String,
    rangeKey: true,
  },
  phoneNumber: {
    type: String,
  }
})

and this method to save the company

export async function addCompany(company) {
  const companyItem = new CompanyModel({
    id: uuid(),
    ...company,
  });
  return new Promise((resolve, reject) => {
    return companyItem.save(function (err) {
      if(err) {
        console.error(err);
        reject(err);
      } else {
        resolve(companyItem);
      }
    })
  });
}

with the following error:

message: 'One of the required keys was not given a value',
  code: 'ValidationException',
  time: 2019-01-24T13:21:11.393Z,
  requestId: '5ea9baca-a6b5-4280-8b1f-4e7596b12909',
  statusCode: 400,
  retryable: false,
  retryDelay: 26.772102945759634

All 10 comments

You need to pass the key (id) as the first attribute in your object model or apply the hashKey option.

So I think it is hashKey as my Definition file for DynamoDB contains "KeySchema": [{ "AttributeName": "id", "KeyType": "HASH" }].

If I pass key id as first attribute

{ id: 'ufW5Ru5xlyZBQYDN2MJBI5M7R4XRdQIw0',
  address: 
   { company: [Getter/Setter],
     name: [Getter/Setter],
     street: [Getter/Setter],
     zip: [Getter/Setter],
     city: [Getter/Setter],
     country: [Getter/Setter] }
}

it does not work with the same error as described above.

Can you change the order for the constructor.definition? When it walks
the schema the first attribute is used as the hash key.

On Tue, Mar 7, 2017, 6:09 PM Moritz Pfeiffer (Mo) notifications@github.com
wrote:

So I think it is hashKey as my Definition file for DynamoDB contains "KeySchema":
[{ "AttributeName": "id", "KeyType": "HASH" }].

If I pass key id as first attribute

{ id: 'ufW5Ru5xlyZBQYDN2MJBI5M7R4XRdQIw0',
address:
{ company: [Getter/Setter],
name: [Getter/Setter],
street: [Getter/Setter],
zip: [Getter/Setter],
city: [Getter/Setter],
country: [Getter/Setter] }
}

it does not work with the same error as described above.

—
You are receiving this because you commented.

Reply to this email directly, view it on GitHub
https://github.com/automategreen/dynamoose/issues/113#issuecomment-284890735,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AEzTmYiRoB4xBZ6kd75-zYF0g31SuFwCks5rjeOkgaJpZM4MLuOQ
.

I did as described in my last comment. This is what I used as scheme for model, and there id is the first attribute, isn't it? And then as mentioned it fails with the same error.

What I did there quick and dirty for testing:

var get = function(table, object) {
  var newo = {};
  newo.id = object.id;
  newo.address = object.address;
  console.dir(newo)
  return db.model(table, newo).get(object.id);
};

Short Edit:
even if I only pass {id: object.id} as scheme for the model it fails with the same error. But this should definetely work as only id is a keyHash but not address, isn't it?

Is this still an issue with v0.8.0?

Yes. the same issue on v0.8.6

Dynamoose has gone through a lot of changes recently including the release of Dynamoose version 1.0.0. Due to that I'm closing this issue for now. Please test if this is still an issue on the latest version of Dynamoose, and you still run into problems please open a new issue and fill out all the fields in the issue template so we can properly debug, and mention this issue number in the new issue.

Thanks for using Dynamoose and we look forward to helping further if needed!

Hi

I have the same issue with the following configuration

const CompanySchema = dynamoose.Schema({
  id: {
    type: String,
    hashKey: true,
  },
  companyName: {
    type: String,
    rangeKey: true,
  },
  phoneNumber: {
    type: String,
  }
})

and this method to save the company

export async function addCompany(company) {
  const companyItem = new CompanyModel({
    id: uuid(),
    ...company,
  });
  return new Promise((resolve, reject) => {
    return companyItem.save(function (err) {
      if(err) {
        console.error(err);
        reject(err);
      } else {
        resolve(companyItem);
      }
    })
  });
}

with the following error:

message: 'One of the required keys was not given a value',
  code: 'ValidationException',
  time: 2019-01-24T13:21:11.393Z,
  requestId: '5ea9baca-a6b5-4280-8b1f-4e7596b12909',
  statusCode: 400,
  retryable: false,
  retryDelay: 26.772102945759634

@yashutanna I have never run into this issue before. Is there a way that I can get a complete reproducible example so that I can try to debug this?

I run into the same issue and after a few hours trying to figure out what is going on I found out. This was due to the table being initially created with a certain schema, mine was set to expect a hash attribute of "cardId" then changed to "id" so it was throwing the "ValidationException"

To check what is in the table KeySchema use NoSQL Workbench, go to the table and click on the Metadata tab.

To resolve the issue just delete and create the table again.

Was this page helpful?
0 / 5 - 0 ratings