经过大量的研究,我找到了它为什么不起作用的答案
var AWS = require("aws-sdk");
//AWS.config.loadFromPath('details.json');
AWS.config.update({
accessKeyId: 'XXXXXXXXXXXXXXXX',
secretAccessKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
region: "XXXXXXXXX",
});
var docClient = new AWS.DynamoDB.DocumentClient();
/* Get single item */
var table = "TABLE NAME";
var msgId = 'PRIMARY KEY VALUE';
var params = {
TableName: table,
Key:{
'MsgId': msgId
}
};
docClient.get(params, function(err, data) {
if (err) {
console.error("Unable to read item. Error JSON:", JSON.stringify(err, null, 2));
} else {
console.log("GetItem succeeded:", JSON.stringify(data, null, 2));
}
});
要获取表的所有记录,只需使用下面的scan函数
var table = "PadmanStopsTest";
var params = {
TableName: table,
};
docClient.scan(params, function(err, data) {
if (err) {
console.error("Unable to read item. Error JSON:", JSON.stringify(err, null, 2));
} else {
console.log("GetItem succeeded:", JSON.stringify(data, null, 2));
}
});
不需要终点只需要通过
accessKeyId
secretAccessKey
和
region
. 我在params中传递电子邮件,所以这里我们需要传递表的主键值。
我通过了考试,对我来说很好。