Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Attribute may not contain an empty string

I am parsing a CSV file and putting the data in a table with AWS DynamoDB.

As it stands right now, I am getting the following error:

One or more parameter values were invalid: An AttributeValue may not contain an empty string

... BEFORE it puts the data in the table. The data is getting to the table, but not before spamming me with that error a million times.

My Code:

var csv = require("fast-csv");

csv.fromPath(file, {
        headers: true,
        ignoreEmpty: true
    })
    .on("data", function(data) {

        for (var key in data) {
            if (data.hasOwnProperty(key)) {
                if (data[key] === "" || data[key] === undefined || data[key] === null) {
                    data[key] = "N/A";
                }
            }

            params = {
                TableName: tableName,
                Item: {
                    RefID: {
                        S: data["Ref-ID"]
                    },
                    //lots of other data
                }
            };
            dynamodb.putItem(params, function(err, data) {
                if (err) {
                    console.error("Unable to add item. Error JSON:", JSON.stringify(err, null, 2));
                }
                else {
                    console.log("Added item:", JSON.stringify(data, null, 2));
                }
            });
        }

    })
    .on("end", function() {
        console.log("done");
    });

As you can see, I am converting any possible empty strings to == N/A in an attempt to solve this problem. Any thoughts?

EDIT:

This turns out to be undefined when it should display what it put in the table.

console.log("Added item:", JSON.stringify(data[key], null, 2));

EDIT 2: Changed this code...

dynamodb.putItem(params, function(err, data)

...to this:

dynamodb.putItem(params, function(err, info)

I am still getting the errors, but am now displaying the table correctly.

like image 766
FF5Ninja Avatar asked Aug 03 '16 18:08

FF5Ninja


1 Answers

It appears that dynamoDB at this time does not allow empty strings. I can NOT understand why, but as of this date you cannot not store an attribute of "Key":"".

Please complain to amazon about it. key="" and key=null are very different use cases and are needed.

like image 114
Tim Meade Avatar answered Nov 02 '22 23:11

Tim Meade