1 Answer
- Newest
- Most votes
- Most comments
3
To resolve the DynamoDbException: Query key condition not supported error in your DynamoDB query, ensure the partition key and sort key are used correctly in the QueryConditional.sortBeginsWith method.
Correct Query Code:
Flux.from(tablePrimary.query(
QueryEnhancedRequest.builder()
.queryConditional(QueryConditional.sortBeginsWith(
k -> k.partitionValue(notificationId)
.sortValue(entityId)
))
.build()
)
.items()
)
Key Points: 1.Partition Key First: Specify partitionValue(notificationId) before sortValue(entityId).
2.Correct Method Usage: Ensure the lambda correctly sets both partition and sort values.
Example with Error Handling:
Flux.from(tablePrimary.query(
QueryEnhancedRequest.builder()
.queryConditional(QueryConditional.sortBeginsWith(
k -> k.partitionValue(notificationId)
.sortValue(entityId)
))
.build()
)
.items()
)
.onErrorResume(e -> {
// Log the error
System.err.println("Error querying DynamoDB: " + e.getMessage());
return Flux.empty();
})
.subscribe(item -> {
// Process the item
System.out.println(item);
});
Table Structure: Verify that your DynamoDB table has the partition key notificationId and the sort key entityId defined correctly.
By following this structure, your query should work without the Query key condition not supported error. i hope this will helps you, thank you
Relevant content
- Accepted Answerasked a year ago
- AWS OFFICIALUpdated 4 months ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 24 days ago
I tried with partitionKey first and next the sortKey but that still doesn't solve the issue.
here the sort value that I passed to the method contains just the beginning few letters of the actual sort value.