dynobase-icon
Dynobase

Error: dynamodb exclusivestartkey not working

Rafal Wilinski

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.

Dynobase is a Professional GUI Client for DynamoDB

Start your 7-day free trial today

Product Features

Download
/
Pricing
/
Member Portal
/
Privacy
/
EULA
/
Twitter
© 2026 Dynobase
+
Still using AWS DynamoDB Console?
Try Dynobase to accelerate your DynamoDB workflow. Start your 7-day free trial today.