Cma*_*mag 14 amazon-web-services node.js amazon-dynamodb
人们,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);
});
}
Run Code Online (Sandbox Code Playgroud)
输出:
error: UnexpectedParameter: Unexpected key 'username' found in params.Key['0']
Run Code Online (Sandbox Code Playgroud)
谢谢!任何帮助将不胜感激!
Cma*_*mag 18
必须遵循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();
});
Run Code Online (Sandbox Code Playgroud)
我试图按照文档中的建议进行操作,但也遇到了错误。
最后,以下工作有效:
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();
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
30112 次 |
最近记录: |