【发布时间】:2021-03-13 04:58:20
【问题描述】:
我正在尝试从 dynamoDB 中获取 getItem 函数之外的数据,但我遇到了这个错误,我不知道为什么。
Error ValidationException: Supplied AttributeValue is empty, must contain exactly one of the supported datatypes
这是我的代码
const aws = require("aws-sdk"),
docClient = new aws.DynamoDB.DocumentClient({ apiVersion: "2012-08-10" }),
ddb = new aws.DynamoDB({ apiVersion: "2012-08-10" }),
tableName = "usersDB",
exports.apiKey = async (req, res, context) => {
var params = {
TableName: tableName,
Key: {
"username": { "S": req.body.username },
},
ProjectionExpression: "apiKey"
};
chaveAPI = await ddb.getItem(params, function (err, data) {
if (err) {
console.log("Error", err);
} else {
console.log("Success", data.Item);
}
});
};
EDIT1:修复了验证错误,但仍然无法从 dyname 获取数据。这里是固定的
exports.apiKey = async (req, res) => {
console.log("comecei")
var params = {
TableName: tableName,
Key: {
'username': {S: req.user.username}
},
ProjectionExpression: 'apiKey'
};
// Call DynamoDB to read the item from the table
dataFromDynamo = await ddb.getItem(params, function(err, data) {
if (err) {
console.log("Error", err);
} else {
console.log("Success", data.Item);
return data.Item
}
});
console.log(dataFromDynamo)
};
【问题讨论】:
标签: node.js amazon-web-services amazon-dynamodb