Here's the deal:
I am not able to add data to DynamoDB. JS file is in S3, here's the code:
var date = new Date(),
item = {
'id': {N: date.getTime()},
'user': {S: "Sam"}
},
params = {
TableName: 'users',
Item: item
};
dynamodb.putItem(params,function(err,data){
if (err) {
console.log(err);
} else {
console.log("user added to DynamoDB");
}
});
Here's the screenshot from the DB which means that the id
should be a number, not string:
The error I get:
Error: Expected params.Item['id'].N to be a string
at ParamValidator.fail (aws-sdk.js:96666) at ParamValidator.validateType (aws-sdk.js:96827) at ParamValidator.validateString (aws-sdk.js:96762) at ParamValidator.validateScalar (aws-sdk.js:96742) at ParamValidator.validateMember (aws-sdk.js:96709) at ParamValidator.validateStructure (aws-sdk.js:96690) at ParamValidator.validateMember (aws-sdk.js:96703) at ParamValidator.validateMap (aws-sdk.js:96729) at ParamValidator.validateMember (aws-sdk.js:96707) at ParamValidator.validateStructure (aws-sdk.js:96690)
I just had the issue myself.
Dynamo expect the "N" value to be a string, it's a bit misleading since you expect to pass a number to it.
where you have your date.getTime(), try to translate it into a string.
'id': { N: date.getTime().toString() },
That worked for me.
Even when you want to save the value as a number in DynamoDB, you still need to send a string to the SDK, and so, you'll need to:
var date = new Date(),
item = {
'id': {N: date.getTime().toString()},
'user': {S: "Sam"}
},
params = {
TableName: 'users',
Item: item
};
dynamodb.putItem(params,function(err,data){
if (err) {
console.log(err);
} else {
console.log("user added to DynamoDB");
}
});
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