4

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?

tom q
  • 97
  • 2
  • 6

1 Answers1

2

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.