我正在try 创建一个过滤器,以获取DynamoDB表中的多条记录.我在AWS Lambda中使用带有NodeJS的函数BatchGetItem作为API.下面是我的助手们的样子.
注意:我try 了多种方法来创建这些参数.我使用了单引号/双引号/不带引号;我还传递了每个项目及其类型({pk:{S:‘Request#10001’}}),但这些都不起作用.
上下文:我的表名为RequestTable,其中有一列名为"PK"(定义为字符串)和"SK"(定义为字符串).如果我在DynamoDB UI中应用完全相同的过滤器(例如:pk=="RequestTM#10001"和SK=="CLIENT"),它就可以工作.
const AWS = require('aws-sdk');
const client = new AWS.DynamoDB();
const params = {
RequestItems: {
"RequestTable": {
Keys: [
{PK: 'Request#10001', 'SK': 'Client'},
{PK: 'Request#10002', 'SK': 'Client'}
]
}
}
}
client.batchGetItem(params, function(err, data) {
if (err) {
console.log("Error", err);
} else {
data.Responses.RequestTable.forEach(function(element, index, array) {
console.log(element);
});
}
});
但是,我无法执行此操作,因为我总是遇到类似以下内容的错误:
Error MultipleValidationErrors: There were 6 validation errors:
* MissingRequiredParameter: Missing required key 'RequestItems' in params
* UnexpectedParameter: Unexpected key 'TableName' found in params
* UnexpectedParameter: Unexpected key 'IndexName' found in params
* UnexpectedParameter: Unexpected key 'KeyConditionExpression' found in params
* UnexpectedParameter: Unexpected key 'ExpressionAttributeNames' found in params
* UnexpectedParameter: Unexpected key 'ExpressionAttributeValues' found in params
我怎么才能解决这个问题呢?
我试着try 使用可用的选项,并试图使其看起来像以下AWS资源:Read in Batch AWS DynamoDB Example个,但没有成功.