Here is my code:
obj = _.chain(obj)
.values()
.map(function(item) {
return item ? item.toString() : "";
})
.value();
DynamoDB.putItem({
"TableName": tblName,
"Item": {
"UserId": { "S": obj.user_id },
"Identifier": { "S": obj.identifier },
"ReferralToken": { "S": obj.referral_token },
"CampaignId": { "S": obj.campaign_id },
"FirstName": { "S": obj.first_name },
"LastName": { "S": obj.last_name },
"Gender": { "S": obj.gender },
"BirthDate": { "S": obj.birthdate },
"Username": { "S": obj.username },
"MobileNumber": { "S": obj.mobile_number },
"PostalCodeText": { "S": obj.postal_code_text },
"Classification": { "S": obj.classification },
"DeliveryEmail": { "S": obj.delivery_email },
"DeliverySMS": { "S": obj.delivery_sms }
}
}, function (err, data) {
console.log(err);
console.log(data);
});
The error I keep getting is:
{ [ValidationException: Supplied AttributeValue is empty, must contain exactly one of the supported datatypes]
message: 'Supplied AttributeValue is empty, must contain exactly one of the supported datatypes',
code: 'ValidationException',
time: Fri Oct 10 2014 11:04:00 GMT-0500 (CDT),
statusCode: 400,
retryable: false }
I am sure I am doing something obviously wrong, I just can't seem to figure out what's wrong
@dennismonsewicz the DynamoDB API does not allow empty strings for items, see here (search for "empty string"). Your code that replaces items with "" is likely what is causing the error.
If you really want to store those empty objects, you might consider using the new NULL type in DynamoDB just released this week, though that would require passing (and parsing) { NULL: true } instead of { S: ... }. You might also want to look at awslabs/dynamodb-document-js-sdk which supports converting null values in a more transparent way using the new NULL types.
Thanks so much for the help! I think I figured out my issue.
It appears even if you label an item as an N type, you have to convert it the item to a string. So your object mapping would look like...
{ "N": "1234" }
@dennismonsewicz local parameter validation should have caught that one:
var params = {
TableName: 'table',
Item: { session_id: {S:'id'}, numericValue: {N:1234} }
};
dynamodb.putItem(params, function(err, data) {
if (err) console.log(err);
});
// prints:
// InvalidParameterType: Expected params.Item['numericValue'].N to be a string
Did you not get that error? If not, can you provide some code that got the service side error without parameter validation? Or do you have parameter validation disabled?
@dennismonsewicz I'm going to mark this as closed since it seems like you've resolved your issue. If you can chime in about the questions I asked above, that would be great!
@lsegal so sorry for the delay, been heads down on this project and forgot to chime back in.
Shouldn't declaring a value of N be saved as Numeric type?
N: "1234" Always needs double quotations to be converted to a string. What I'm trying to figure out is if you change "N" to an event?
Example:
Change N: "1234" to N: event.something
Something being an attribute. That's when I get the error Supplied AttributeValue is empty,
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.
Most helpful comment
@dennismonsewicz the DynamoDB API does not allow empty strings for items, see here (search for "empty string"). Your code that replaces items with "" is likely what is causing the error.
If you really want to store those empty objects, you might consider using the new
NULLtype in DynamoDB just released this week, though that would require passing (and parsing){ NULL: true }instead of{ S: ... }. You might also want to look at awslabs/dynamodb-document-js-sdk which supports converting null values in a more transparent way using the newNULLtypes.