Error: DynamoDB Query Limit Not Working

Answered by Rafal Wilinski
Last updated: October 23rd, 2026
Solution
DynamoDB Query Limit caps items evaluated before FilterExpression, not the number of matching items returned. With Limit set to 10, DynamoDB may return fewer than 10 matches, including zero, and still supply LastEvaluatedKey.
Continue from that key until enough matches are collected or no continuation key remains. For example, with the v3 document client db and QueryCommand:
const matches = [];
let key;
const wanted = 10;
do {
const page = await db.send(new QueryCommand({
TableName: "Orders",
KeyConditionExpression: "pk = :pk",
FilterExpression: "#status = :status",
ExpressionAttributeNames: { "#status": "status" },
ExpressionAttributeValues: { ":pk": "CUSTOMER#123", ":status": "OPEN" },
Limit: wanted - matches.length,
ExclusiveStartKey: key,
}));
matches.push(...(page.Items ?? []));
key = page.LastEvaluatedKey;
} while (matches.length < wanted && key && Object.keys(key).length > 0);The service page-size boundary can stop a request before Limit is reached. Preserve the final continuation key if the user can request another page. SDK paginators and the AWS CLI may automatically fetch multiple service pages, so their page-size setting is not necessarily a total-result cap. Filtering many pages to find a few items can be expensive; consider an index matching the access pattern.
See pagination examples and AWS documentation.
Other Common DynamoDB Errors (with Solutions)
- dynamodb cannot create preexisting table
- dynamodb index does not exist
- DynamoDB scan does not return all items
- dynamodb problem function call failed
- dynamodb the parameter cannot be converted to a numeric value
- DynamoDB throttling error
- dynamodb local could not load credentials from any providers
- DynamoDB console unable to delete this item
- DynamoDB Internal Server Error
- can't pickle thread.lock objects typeerror boto3 python dynamodb
- Unable to start DynamoDB Local process
- dynamodb global secondary index not working
- aws.dynamodb.converter.unmarshall not working
- DynamoDB Local Docker Not Working
- com amazonaws services dynamodbv2 model resourcenotfoundexception
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