【发布时间】:2020-10-07 20:07:13
【问题描述】:
我遇到了一个奇怪的问题,当我指定一个以 ID 结尾的参数时,dynamodb.getItem 返回 {}:
var AWS = require("aws-sdk");
AWS.config.update({ region: "ap-southeast-2" });
var dynamodb = new AWS.DynamoDB({ apiVersion: '2012-08-10' });
const tableName = "ReportingDB"
async function logReports() {
try {
var params = {
Key: {
"Category": { "S": "Certification" },
"Report": { "S": "By EmployeeID" }
},
TableName: tableName
};
var result = await dynamodb.getItem(params).promise()
console.log(JSON.stringify(result))
} catch (error) {
console.error(error);
}
}
当我将值“By EmployeeID”更改为“By Employee Number”时,它会起作用,为什么?
async function logReports() {
try {
var params = {
Key: {
"Category": { "S": "Certification" },
"Report": { "S": "By Employee Number" }
},
TableName: tableName
};
var result = await dynamodb.getItem(params).promise()
console.log(JSON.stringify(result))
} catch (error) {
console.error(error);
}
}
要重现,请创建一个包含 Category 和 Report 两列的 DynamoDB 表,然后分别添加一个具有“Certification”和“By EmployeeID/Number”值的项目。
DynamoDB 中的错误处理非常好,通常它会失败并显示错误消息,例如保留关键字(例如 Using a ProjectionExpression with reserved words with Boto3 in DynamoDB)但是使用“By EmployeeID”它不会产生任何错误,它只是不会返回任何事物。它可能是一个错误或我不知道的东西吗?我找不到它的文档。
PS 我已经使用 Web 控制台在 dynamo db 中插入了值。
【问题讨论】:
标签: node.js amazon-web-services amazon-dynamodb