question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DynamoDB query throws ValidationException

See original GitHub issue

When I try to do an empty query:

dynamodb = boto3.resource("dynamodb", endpoint_url="http://localhost:7000")
table = dynamodb.Table(table_name)
response = table.query(
    )

I get an error stating that the KeyConditionExpression parameter needs to be passed:

botocore.exceptions.ClientError: An error occurred (ValidationException) when calling the Query operation: Either the KeyConditions or KeyConditionExpression parameter must be specified in the request.

However in the Amazon Docs it says the KeyConditionExpression is not a required parameter.

I’m trying to query my entire table for all the rows and running a scan is not feasible in my scenario since I need the response to be automatically sorted. Any suggestions?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

7reactions
yaynickcommented, Dec 11, 2015

Wow I don’t think any amount rereading it would have allowed me to interpret it like that, so many thanks for the explanation.

As for the comparison rules, that I definitely overlooked! Now I see the fine print: You must specify the partition key name and value as an equality condition.

Which explains why I couldn’t just do KeyConditionExpression=Key('category').between('a', 'z') as it throws a ValidationException.

2reactions
kyleknapcommented, Dec 11, 2015

The docs cannot mark either of them as a required in the docs because if a parameter is marked as required it will be a hard fail if the parameter is not even part of the request (it does not matter what other parameters were provided). So for example:

  • If KeyCondition is marked as required, then users would not be able to just only provide KeyConditionExpression (which is recommend) because KeyCondition is not in the request.
  • If KeyConditionExpression was marked as required, that would break users previously using only KeyCondition because they now have to provide KeyConditionExpression instead.
  • Then you cannot mark both as required because that would cause conflicting queries or be redundant.

Yeah so if you have a partition key and a sort key, you would have to provide the partition key in the query as that is required when querying. You can also provide a sort key as well though to narrow down the results returned back, and this has more comparisons available to it than the partition key’s equality comparison. Here is more specifics in the docs about what you must provide for queries: http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/QueryAndScan.html#QueryAndScan.Query.

To get this working, I think you will need to rely on querying over each category as the partition key can only rely on the eq() comparison. Let us know if you have anymore questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error handling with DynamoDB - AWS Documentation
When your program sends a request, DynamoDB attempts to process it. If the request is successful, DynamoDB returns an HTTP success status code...
Read more >
DynamoDB Validation Exception - Key element does not ...
You are getting this error because when using AWS.DynamoDB.DocumentClient.get method, you must specify both hash and sort key of an item.
Read more >
Common DynamoDB Errors (and Solutions) - Dynobase
This page is a compilation of the most common DynamoDB user/system errors and ... DynamoDB ValidationException: Query condition missed key schema element ...
Read more >
AmazonDynamoDB (AWS Java SDK for Amazon DynamoDB ...
The response from the Query service method, as returned by AmazonDynamoDBv2. Throws: ResourceNotFoundException · ProvisionedThroughputExceededException ...
Read more >
DynamoDB - Quick Guide - Tutorialspoint
Though DynamoDB does not force their use, they optimize querying. ... public static void main(String[] args) throws Exception { AmazonDynamoDBClient client ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found