16

伙计们,Javascript 新手...尝试从节点进行简单的发电机查询:

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']

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

4

3 回答 3

19

必须遵循 SDK 和文档,很简单: 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();
  });
于 2013-09-29T15:22:52.617 回答
3

我试图按照文档中的建议进行操作,但也出现了错误。

最后,以下工作:

var aws = require('aws-sdk');
var db = new aws.DynamoDB({
  region: 'eu-central-1',
  maxRetries: 1
});

exports.handler = event => {
    return queryMyThings();
}

const queryMyThings = async (event) => { 
 var params = {
      Key: {
      "ColumnByWhichYouSearch": {
         S: "ValueThatYouAreQueriing"
        }
      }, 
      TableName: "YourTableName"
     };

    return await db.getItem(params).promise();

}
于 2020-05-20T10:52:04.227 回答
0

以下是使用 NodeJS 的 DynamoDB 的重要资源:

于 2016-02-02T23:00:11.637 回答