Error: dynamodb exclusivestartkey not working

Answered by Rafal Wilinski
Last updated: October 23rd, 2026
Solution
ExclusiveStartKey works when you pass the previous response’s LastEvaluatedKey into the next request without changing its key names or types. A filtered page with no returned items can still have a continuation key. Stop on a missing or empty key, not on an empty Items array.
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { DynamoDBDocumentClient, QueryCommand } from "@aws-sdk/lib-dynamodb";
const db = DynamoDBDocumentClient.from(new DynamoDBClient({ region: "us-east-1" }));
let cursor;
do {
const page = await db.send(new QueryCommand({
TableName: "Orders",
KeyConditionExpression: "pk = :pk",
ExpressionAttributeValues: { ":pk": "CUSTOMER#123" },
ExclusiveStartKey: cursor
}));
for (const item of page.Items ?? []) console.log(item);
cursor = page.LastEvaluatedKey;
} while (cursor && Object.keys(cursor).length);Keep the table, index, key condition, and value types consistent across pages. An index cursor can contain both index and table key attributes; preserve all of it. A low-level client uses AttributeValue objects, while the document client uses native values. Do not transfer a cursor between those formats without conversion.
DynamoDB pagination keys are not expiring authentication tokens. Concurrent writes can change the result set because pagination is not a snapshot. For parallel Scan, use each cursor with the same Segment that produced it. For application-facing cursors, preserve the values losslessly and bind them to the original query.
See pagination examples and AWS documentation.
Other Common DynamoDB Errors (with Solutions)
- Error retrieving DynamoDB table item validation exception
- DynamoDB Error All Attributes Must Be Indexed
- dynamodb global secondary index not working
- dynamodb could not instantiate class
- dynamodb could not connect to the endpoint url
- DynamoDB table not updating
- DynamoDB string set cannot be empty
- DynamoDB missing items
- could not lookup table in dynamodb
- dynamodb table not exists
- dynamodb system errors metric
- ProvisionedThroughputExceededException DynamoDB
- dynamodb ttl not deleting / erasing items
- DynamoDB stream lambda error
- dynamodb unable to execute http request
Dynobase is a Professional GUI Client for DynamoDB
Start your 7-day free trial today