I have a dynamodb table with string primary key called name
and number sort key age
. I want to get the items in the dynamodb table with age
younger than 30. I understand that since my filter is on a Key, I can use query instead of scan.
So I tried: response = table.query( KeyConditionExpression=Key('age').lt(decimal.Decimal(30)) ) response
But this returns the response:
ClientError: An error occurred (ValidationException) when calling the Query operation: Query condition missed key schema element: name
So it looks like i need to provide a partition key for queries? Does this mean I can only make queries for age given a name?
What is the code to do this in boto3?
Yes, it's true. The query
needs the partition key, as it runs on a specific partition only.
You need to use the scan
and filter
in your use case, but this can be a little expensive depending on the size of your table.
The ideal solution would be to keep track of all your partition keys and do parallel queries on them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With