【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
asked 16 days ago107 views
No Answers

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions