Error: dynamodb query key condition not supported

Answered by Rafal Wilinski
Last updated: October 23rd, 2026
Solution
Query key condition not supported means the expression does not match the target key schema or uses an unsupported key operator. For a table with a partition key and optional sort key, partition-key equality is required; a sort-key condition is optional.
Use = on the partition key. For the sort key, supported comparisons include =, <, <=, >, >= and BETWEEN. String and Binary sort keys also support begins_with. BETWEEN is not restricted to Number keys.
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { DynamoDBDocumentClient, QueryCommand } from "@aws-sdk/lib-dynamodb";
const db = DynamoDBDocumentClient.from(new DynamoDBClient({}));
const result = await db.send(new QueryCommand({
TableName: "Orders",
KeyConditionExpression: "pk = :pk AND begins_with(sk, :prefix)",
ExpressionAttributeValues: { ":pk": "CUSTOMER#123", ":prefix": "ORDER#" },
}));Do not use contains, OR, IN or non-key attributes in a conventional key condition. Move non-key criteria to FilterExpression, or choose a suitable index. When supplying IndexName, use that index's schema. Multi-attribute GSI keys have additional ordering rules; supply all partition-key attributes and follow the declared sort-key order.
See query guidance and AWS documentation.
Other Common DynamoDB Errors (with Solutions)
- dynamodb scan missing values
- dynamodb the table does not have the specified index
- dynamodb the parameter cannot be converted to a numeric value NaN
- DynamoDB Contains not working
- dynamodb unable to execute http request
- DynamoDB scan filter expression not working
- can't pickle thread.lock objects typeerror boto3 python dynamodb
- AWS CLI DynamoDB Error Parsing Parameter
- DynamoDB ConditionalCheckFailedException
- dynamodb does not support null values
- dynamodb converter not found for enhancedtype
- DynamoDB Scan Not Working
- dynamodb update fail if not exists
- DynamoDB attribute not empty
- DynamoDB Expression Not Null
Dynobase is a Professional GUI Client for DynamoDB
Start your 7-day free trial today
Product Features
DynamoDB Tools
- SSH GUI Client
- Chat With Cloud
- MongoDB GUI Client
- AWS Cost Monitoring
- DynamoDB Query Builder
- DynamoDB Code Examples
- DynamoDB Node.js Queries
- DynamoDB JSON Converter
- DynamoDB UUID Generator
- DynamoDB Local Admin GUI
- DynamoDB Pricing Calculator
- DynamoDB Single-Table Design
- Best DynamoDB GUI Clients
- Dynobase vs DynoTable