我正在使用 Lambda 函数,该函数从 dynamoDB 表中的用户 ID 获取用户电子邮件。我使用 dynamoDB 扫描命令扫描 dynamoDB 表中的所有项目。我使用新的 v3 AWS JS 开发工具包。
问题:为什么ExpressionAttributeNames在我的情况下不能正常工作?
这有效:
const params = {
FilterExpression: "user_info.user_id = :userid",
ExpressionAttributeValues: {
":userid": { S: user_id }
},
ProjectionExpression: "user_email",
TableName: aws_table,
}
但这不起作用,为什么?
const params = {
FilterExpression: "#xyz = :userid",
ExpressionAttributeNames: {
"#xyz": "user_info.user_id" // <- filter does not work like this (returns 0 findings)
},
ExpressionAttributeValues: {
":userid": { S: user_id }
},
ProjectionExpression: "user_email",
TableName: aws_table,
};
我的 Lambda 扫描操作代码本身如下所示:
const { DynamoDBClient } = require("@aws-sdk/client-dynamodb");
const { ScanCommand } = require("@aws-sdk/client-dynamodb");
const ddbClient = new DynamoDBClient({ region: aws_region });
...
const run = async () => {
try {
const data = await ddbClient.send(new ScanCommand(params));
data.Items.forEach(function (element, index, array) {
console.log(element);
});
return data;
} catch (err) {
console.log("Error", err);
}
}
await run();
npm i @aws-sdk/client-dynamodb
文档: