aws-sdk-js: [Feedback Requested] [Question] Both DynamoDB.putItem and DocClient.put return "There were x validation errors: InvalidParameterType"

I’m using DynamoDB/DocumentCient on Lambda, and attempting a simple put operation, thusly:

var doc = require('dynamodb-doc');
var dynamo = new doc.DynamoDB();
...
var params = {
    "TableName": "Recipients",
    "Item": {
       "recipient_id": 'XXX',
        "user_id": 'XXX'
    }
};
                        
dynamo.putItem(params, function(err, res) {
    ...

and also:

var AWS = require('aws-sdk');
var docClient = new AWS.DynamoDB.DocumentClient({region: 'us-west-2'});
...
docClient.put(params, function(err, res) {
    ...

However both are returning the same error, as if they are expecting AttributeValue values for the Item:

{
  "errorMessage": "There were 8 validation errors:\n* InvalidParameterType: Expected params.Item['recipient_id'] to be a structure\n* UnexpectedParameter: Unexpected key '0' found in params.Item['recipient_id']\n* UnexpectedParameter: Unexpected key '1' found in params.Item['recipient_id']\n* UnexpectedParameter: Unexpected key '2' found in params.Item['recipient_id']\n* InvalidParameterType: Expected params.Item['user_id'] to be a structure\n* UnexpectedParameter: Unexpected key '0' found in params.Item['user_id']\n* UnexpectedParameter: Unexpected key '1' found in params.Item['user_id']\n* UnexpectedParameter: Unexpected key '2' found in params.Item['user_id']",
  "errorType": "MultipleValidationErrors",

I have tried both the Lambda-included aws-sdk, as well as bundling it myself, but both yield the same results.

Can someone please tell me what silly mistake I’m making?

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 1
  • Comments: 17 (2 by maintainers)

Most upvoted comments

@var1ableX You saved my life! I had prototypes on Object and everything magically stopped working. Prototypes removed and everything works now!

@supportcoinsafer - might want to double check whether you’ve added any prototypes to Object. Or added another library that may have done something like that.