Get All Items from DynamoDB in Node.js (AWS SDK v3)

There is no "select all" in DynamoDB — reading a whole table means a Scan you paginate to the end. Each response carries at most 1 MB; you loop, feeding LastEvaluatedKey back as ExclusiveStartKey, until no key comes back.

Code

import {DynamoDBClient, ScanCommand} from '@aws-sdk/client-dynamodb';

const client = new DynamoDBClient({region: 'us-east-1'});

const items = [];
let lastEvaluatedKey;

do {
  const response = await client.send(
    new ScanCommand({
      TableName: 'Music',
      ExclusiveStartKey: lastEvaluatedKey
    })
  );

  items.push(...(response.Items ?? []));
  lastEvaluatedKey = response.LastEvaluatedKey;
} while (lastEvaluatedKey);

console.log(`Table holds ${items.length} items`);

Explanation

  • The loop is the point — a single Scan call does NOT return the table; it returns up to 1 MB. Stopping after the first response is the classic "my scan is missing items" bug. Only an absent LastEvaluatedKey means you've read everything.
  • Memoryitems holds the entire table. For big tables, process each page inside the loop (write to a file, stream, aggregate) instead of accumulating.
  • Faster on big tables: parallel scan — split the work with Segment / TotalSegments: run N workers, each scanning its own segment with its own pagination loop. Same total cost, much lower wall-clock time.
  • Cost — a full scan reads (and bills) every byte of every item, every time you run it. Trim the response with ProjectionExpression (fewer attributes returned — the read cost stays the same), and don't put a scan on a hot path; that's what Query and access-pattern design are for.
  • Filtering while you're at it? A FilterExpression drops items after they're read (and billed) — see Scan with a filter.

Do it visually

Eyeballing a table doesn't need a script: download DynoTable to browse any table in a paginated grid — it pages through scans for you, no loop to get wrong. And before you scan-and-pay, the DynamoDB pricing calculator shows what a full read of your table actually costs.

References

Last verified 2026-07-13 against the official AWS documentation linked above.

Build this request visually

Compose this operation in the free DynamoDB Query Builder — key condition, filter, index, Limit, sort order, and a pagination loop — and copy it back as a runnable SDK v3, CLI, or boto3 program.

Open the DynamoDB Query Builder

Work with DynamoDB without the Console

DynoTable is a fast desktop client for DynamoDB — browse tables, run SQL-style queries, and edit items locally.