dynamodb节点aws-sdk简单getItem()调用

Folks,Javascript to new …试图从节点做简单的发电机查询:

var AWS = require('aws-sdk'); AWS.config.update({region: 'us-east-1'}); var db = new AWS.DynamoDB(); var params = { "TableName" : 'admins', "Key" : [ { "username" : { "S" : "foo" } }, ], } db.getItem(params, function(err, data) { console.log('error: '+ err); console.log(data); return next(); res.send(data); }); } 

输出:

 error: UnexpectedParameter: Unexpected key 'username' found in params.Key['0'] 

谢谢! 任何帮助将不胜感激!

       

网上收集的解决方案 "dynamodb节点aws-sdk简单getItem()调用"

必须遵循SDK和Docs,其简单: http : //docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_GetItem.html

 var params = { AttributesToGet: [ "password" ], TableName : 'foo', Key : { "username" : { "S" : "bar" } } } db.getItem(params, function(err, data) { if (err) { console.log(err); // an error occurred } else { console.log(data); // successful response res.send(data); } return next(); }); 

以下是使用Node js的DynamoDB的丰富资源:

入门指南: http : //docs.aws.amazon.com/amazondynamodb/latest/gettingstartedguide/GettingStarted.NodeJs.html

Documentaion和示例: http : //docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB.html

如果您使用的是DocumentClient:

http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html