查询全局二级索引:'MissingRequiredParameter:缺少必需的键

Querying a Global Secondary Index: 'MissingRequiredParameter: Missing required key

我有一个像这样的 DynamoDB table 定义:

{
"pk": {
  "S": "00000000-0000-0000-0000-000000000001"
},
"sk": {
  "S": "00000000-0000-0000-0000-000000000001"
},
"year": {
  "N": "2019"
}
"index": {
  "N": "987654321"
}
}

其中 "pk" 是分区键。 "sk" 是排序键。如果您想知道为什么 pk 和 sk 具有相同的值:Adjacency List Design Pattern.

我已经在属性 "index" 上创建了一个全局二级索引。它的投影都是键,pk 和 sk。

现在,following the documentation 我正在这样查询我的 GSI:

        const params = {
                TableName: 'my_table_name',
                IndexName: 'my_index_name',
                KeyConditionExpression: "index = :v_index",
                ExpressionAttributeValues: {
                    ":v_index": {"N": 987654321}
                },
                ProjectionExpression: "pk",
                ScanIndexForward: false
            };

我收到以下错误消息:'MissingRequiredParameter:params\n

中缺少必需的键 \'Key\'

以防万一,我在 Lambda

中使用 Node.js 8.10

一般来说,对于同一个 GSI 主键 + 辅助键组合,GSI 可以有多个条目。因此,您不能使用 getItem() 调用来检索对象。针对 GSI 的查询需要是 scanquery

亚马逊关于working with GSIs

的文档的前几行中提到了这一点