DynamoDB query throws ValidationException
See original GitHub issueWhen 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:
- Created 8 years ago
- Comments:6 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.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:
KeyCondition
is marked as required, then users would not be able to just only provideKeyConditionExpression
(which is recommend) becauseKeyCondition
is not in the request.KeyConditionExpression
was marked as required, that would break users previously using onlyKeyCondition
because they now have to provideKeyConditionExpression
instead.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.