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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With