Dynamodb error : Either the keyconditions or keyconditionexpression parameter must be specified in the request

timblistic picture timblistic · Nov 23, 2017 · Viewed 8.8k times · Source

I am observing an unexpected outcome when querying a DynamoDB table using the AWS DynamodB Document Model in C#.

My table users has a username primary key. The GSI was set in for user_type, user_id and username keys.

Querying my dynamodb

This table works when I insert a document, but when querying a non-indexed but GSI-ed column, it returns this error:

Either the KeyConditions or KeyConditionExpression parameter must be specified in the request.

I have specified the condition in a filter object. Why am I asked to provide KeyConditions or KeyConditionExpression? Is it mandatory to specify them? If yes, how do I do that?

Answer

F_SO_K picture F_SO_K · Nov 23, 2017

Its not 100% clear from the documentation but I believe if you are using the DocumentModel library Query will only work if your GSI has a range key as well as partition key. Instead I would consider using the standard sdk QueryRequest

Another thing to check is that you are using Amazon.DynamoDBv2.DocumentModel, because in version 1 you have to specify the haskey explicitly