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.
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.
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