Error: DynamoDB sorting is not supported for scan expressions

Answered by Rafal Wilinski
Last updated: October 23rd, 2026
Solution
DynamoDB Scan does not support sorting results. ScanIndexForward belongs to Query and cannot order a Scan. For ordered access, query a table or index whose sort key represents the desired ordering, within the specified partition-key value.
const params = {
TableName: "Orders",
KeyConditionExpression: "pk = :pk",
ExpressionAttributeValues: { ":pk": "CUSTOMER#123" },
ScanIndexForward: false
};
// Use SDK v3 QueryCommand with DynamoDBDocumentClient.
// This table's sort key must encode the intended ordering.Query returns ascending sort-key order by default; false reverses it. Numeric sort keys sort numerically, while string sort keys follow UTF-8 byte order. An index can support another ordering, but it does not provide an unrestricted globally sorted table scan.
For small datasets, collect every Scan page and sort the complete result in application memory. Sorting each page independently does not produce a globally sorted result. For large analytical datasets, export or replicate to an appropriate query engine rather than repeatedly scanning and sorting the live table.
See sort-key design and AWS documentation.
Other Common DynamoDB Errors (with Solutions)
- why is the GSI dynamodb not showing item count
- DynamoDB validation error
- ImportError: No module named boto3 (DynamoDB)
- dynamodb query is not null
- aws.dynamodb.documentclient is not a constructor
- dynamodb the parameter cannot be converted to a numeric value
- Dynamodb error 500
- DynamoDB table not updating
- missing required key 'key' in params dynamodb
- CORS Error DynamoDB
- DynamoDB Is Not Null
- dynamodb does not support null values
- could not unmarshal the value dynamodb
- DynamoDB Update Not Working
- DynamoDB ValidationException: Query condition missed key schema element
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