Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NodeJS with DynamoDB throws error "AttributeValue may not contain an empty string"

I had a problem with the fact that DynamoDB cannot accept empty strings as value in attributes. I always had to check in the front end if there is an empty string value otherwise the API call would fail due to the error "An AttributeValue may not contain an empty string" that Dynamo DB would throw.

I was wandering if there is a recursive function that would remove the attributes that are not valid according to DynamoDB in order for the putItem or update request in DynamoDB to work.

like image 520
anestis Avatar asked May 27 '16 09:05

anestis


2 Answers

June 2020 Update:

DynamoDB now supports empty string values for non-key attributes: https://aws.amazon.com/about-aws/whats-new/2020/05/amazon-dynamodb-now-supports-empty-values-for-non-key-string-and-binary-attributes-in-dynamodb-tables/

In order to have consistent behavior, make sure that the client does not have { convertEmptyValues: true }, or else these attributes will be saved as NULL as opposed to an empty String.

like image 59
Aaron_H Avatar answered Oct 26 '22 23:10

Aaron_H


Latest update on Jan 3 2017 Merge #1283 updated the AWS.DynamoDB.DocumentClient constructor-property to allow for empty values by putting the flag convertEmptyValues into the options field of the client object.

Example:

const DynamoDB = new AWS.DynamoDB.DocumentClient( {
    convertEmptyValues: true
} );


Notable issues

  • DynamoDB.DocumentClient should support empty string properties #833
  • Respect convertEmptyValues option for Maps and Lists in the DynamoDB document client #1281
  • Fix/doc client empty nested members #1283
  • AWS Forum threadID #90137
  • Empty Attribute would cause ValidationException for DynamoDb boto/boto3 #1035
like image 39
iSkore Avatar answered Oct 26 '22 23:10

iSkore