0

I have a table in Dynamo Db with 2 million records. The table has date (yyyy-mm-dd) as partition key and account I'd as sort key. Currently, we are using boto3.client.dynamodb.query to fetch the data based on KeyConditionExpression where X is date. I want to query the records based on just year? What should KeyConditionExpression and Expression Attribute Values be?

Sample row in Dynamo Db :

{"date": {"s" : "2022-04-29"},"account_id": {"s" :"6208378688923445"}}

Here date is partition key and account_id is sort key. I want to query all the records with year 2022.

1 Answer 1

1

A query can only operate on a single partition key. If you want to run this query, you need to add a GSI with the year as the partition key. This has additional write and storage costs. If you don’t need to run this query very often, it may be cheaper to just scan the table and filter in the application layer. If you have 2 million records and each record is 500 bytes, the cost of a scan is less than $0.02

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.