将项目放在使用适用于Node.js的AWS开发工具包的DynamoDB表上

我不熟悉javascript和node.js,想知道是否有人可以帮助我找出通过node.js SDK将新项目放到AWS Dynamodb上现有表的语法。 这是我迄今为止。 有什么我想要做的例子吗? 如果有人能指出我的方向正确的话,我会非常感激。

var AWS = require('aws-sdk'); AWS.config.loadFromPath('./config.json'); AWS.config.update({region: 'us-east-1'}); var dynamodb = new AWS.DynamoDB(); var item = { // I need to put the an item with a the primary key of "id", and an attribute called "item" // I'm new to js and node.js, so if somebody could help me understand the documentation // http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/frames.html#!http%3A//docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB_20120810.html } dynamodb.putItem({TableName: 'log_dev', Item: item}, function(err, data){ if (err) { console.log(err); // an error occurred } else { console.log(data); // successful response } }); 

 dynamoDB.putItem( { "TableName": "Table1", "Item": { "Color": {"S": "white"}, "Name": {"S": "fancy vase"}, "Weight": {"N": "2"}, "LastName":{"S": "Kumar"} } }, function(result) { result.on('data', function(chunk) { console.log("" + chunk); }); }); console.log("Items are succesfully ingested in table .................."); 

我希望你的“ID”是数字…

 var item = { "id": {"N": 1234}, "title": {"S": "Foobar"} } 

请注意,使用DynamoDB,您只能在创build表时指定数据types( N »数字, S »string, B »二进制),仅用于主键( HashKeyHashKey + RangeKey )。 所有其他列允许在其数据types上有所不同,并且可以看作是键值对。 因此,DynamoDB始终使用项目属性对数据types进行编码是非常重要的。

我不认为muhqu的答案是有效的,我相信属性的价值必须是一个string。

 var item = { "id": {"N": "1234"}, "title": {"S": "Foobar"} } 

http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB.html#putItem-property