在不使用 SCAN 的情况下获取与非关键属性 dynamoDB 匹配的所有记录

Fetch all records which matches to non key attribute dynamoDB without using SCAN

如果布尔值为真,我需要获取所有记录。 DynamoDB 中的示例我有 3 个属性。 (属性 1-PK 和属性 2-SK)。现在基于非关键属性 3 需要获取所有记录 if attribute3=true.

attribute1   attribute2     attribute3
test            1234           false
test1           1235           true
test2           1236           true
test3           1237           false

请提供我最好的使用方法。我看到使用 SCAN 它可以工作,但使用扫描成本太高。需要替代解决方案。

这是 DynamoDB 中全局二级索引 (GSI) 的用例。

https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GSI.html

attribute3 上添加一个名为 attribute3-index 的 GSI,并使用 DynamoDB query API 和 IndexName="attribute3-index"(语法可能会有所不同,具体取决于您是否使用AWS CLI 或 SDK)。

以下是一些示例 API 调用: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GCICli.html

您还可以考虑本地二级索引,具体取决于您的访问模式。但是,与 GSI 不同的是,本地二级索引必须在 table 创建时创建。

https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-indexes-general.html

一个好的做法是在创建 table 之前规划其访问模式,这样您就可以就创建哪些索引做出最佳决策。