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

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
yashutannacommented, Jan 24, 2019

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
0reactions
jestanoffcommented, Jun 12, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

AWS - One of the required keys was not given a value
If your table has a hash key named Ref-ID then every record you insert will require a value for Ref-ID . This user...
Read more >
[Solved] missing required key 'key' in params dynamodb
This error occurs when the Key attribute has not been provided for the DynamoDB operation. For example, the GetItem or Get (in document...
Read more >
One Of The Required Keys Was Not Given A Value Localstack ...
After reading the documentation and trying to follow examples I am running into this validation error.One of the required keys was not given...
Read more >
Error handling with DynamoDB - AWS Documentation
This error can occur for several reasons, such as a required parameter that is missing, a value that is out of range, or...
Read more >
PutItem - Amazon DynamoDB - AWS Documentation
When you add an item, the primary key attributes are the only required attributes. ... NONE - If ReturnValues is not specified, or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found