amazon-web-services - 如何编写aws dynamodb扫描过滤器
问题描述
我有一个 dynamodb 表,一个记录就像下面这样:
{
"Items": [
{
"toObjectId": {
"S": "5678"
},
"keyValue": {
"S": "7890"
},
"aTypeId": {
"S": "test"
},
"aws:rep:deleting": {
"BOOL": false
},
"currentAt": {
"N": "1582476260000"
},
"keyTypeId": {
"S": "test2"
},
"aId": {
"S": "1234"
},
"aTypeId_keyTypeId_keyValue_currentAt": {
"S": "test_test2_7890_1582476260000"
},
"fromObjectId": {
"S": "12345"
},
}
],
"Count": 2562,
"ScannedCount": 2562,
"ConsumedCapacity": null
}
当aTypeId为“test”时,如何使用aws cli编写一个aws dynamodb扫描/查询过滤器来获取aTypeId和aId?和
Primary partition key is aId (String)
Primary sort key is aTypeId_keyTypeId_keyValue_currentAt (String)
我在下面尝试过,但没有运气
aws dynamodb query \
--table-name test \
--key-condition-expression "aTypeId = :aTypeId" \
--expression-attribute-values '{
":aTypeId": { "S": "test" }
}'
解决方案
您的字段不在键或 GSI(全局二级索引)中,那么我认为您必须使用scan
方法来获取对象aTypeId
,
查询将喜欢:
aws dynamodb scan \
--table-name test \
--filter-expression "aTypeId = :typeValue" \
--projection-expression "aTypeId, aId" \
--expression-attribute-values '{":typeValue":{"S":"test"}}'
如果您返回带有LastEvaluatedKey
值的结果,这意味着您需要进行一个或多个查询来获取所有数据:
aws dynamodb scan \
--table-name test \
--filter-expression "aTypeId = :typeValue" \
--projection-expression "aTypeId, aId" \
--starting-token VALUE_NEXT_TOKEN_OF_LAST_QUERY \
--expression-attribute-values '{":typeValue":{"S":"test"}}'
但是,我建议使用aTypeId
is hash key 创建 GSI 会更好。
推荐阅读
- ros - 测量 Yolo 检测到的物体的尺寸。前任。高度,宽度,与相机的距离
- java - 在 Jboss 上使用 CMS 和 Luna Hsm 解密 p7m
- angular - 从容器 Ref 中包含的组件调用父级函数
- r - 定义要在箱线图中绘制的箱/子组(来自连续变量)(R中的ggplot)
- r - 申请mjca时下标出债券
- sql - PostgreSQL - 启用/禁用触发器是否回滚?
- python - 为 MNIST 数据集打开 .gz 文件
- mysql - 如何在 jenkins 管道中运行 mysql 命令?
- python - 使用 Python 下载电子邮件附件 - 当有多个附件时
- swift - 泛型函数参数默认值