【DynamoDB】 query nested items if sub key exist

0

Here is the item format on dynamodb table

{
 "Products": {
    "ProductGroupA": [
      {
       "Description": "2",
      }
  ],
  "ProductGroupC": [
      {
       "Description": "2",
      }
  ]
 }
}

I attempted to query the item only if the nested key "Products.ProductGroupA" exists:

import boto3

dynamodb = boto3.client('dynamodb')

index_name = 'Products-index'

response = dynamodb.query(
    TableName='my_table',
    IndexName=index_name,
    FilterExpression='attribute_exists(#Products.#a)',
    ExpressionAttributeNames={
        '#Products': 'Products',
        '#a': 'ProductGroupA'
    },
)

However, I always received errors. Is it possible to achieve this goal using the 'query' method of boto3? I want to avoid 'scan' method because of consumption of RCU

If the query is not possible, are there any suggestions? Or should I adjust the structure format of dynamodb table. The reason I tried the nested format is easy to manage, but the reading efficiency makes it hard to implement so much.

Thank you so much. Have a good day !

Ben
已提问 1 个月前116 查看次数
没有答案

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则