Get All Items from DynamoDB in Python (boto3)
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; boto3's built-in scan paginator follows LastEvaluatedKey across every page for you.
Code
import boto3
client = boto3.client("dynamodb")
paginator = client.get_paginator("scan")
items = []
for page in paginator.paginate(TableName="Music"):
items.extend(page["Items"])
print(f"Table holds {len(items)} items")Explanation
- The paginator is the point — a single
scancall does NOT return the table; it returns up to 1 MB.client.get_paginator("scan")issues follow-up requests (feedingLastEvaluatedKeyback asExclusiveStartKey) until the table is exhausted — the loop people forget when they wonder why items are "missing". (Doing it by hand? Keep calling while the response contains aLastEvaluatedKey.) - Memory —
itemsholds the entire table. For big tables, process eachpageinside the loop (write to a file, stream, aggregate) instead of accumulating. - Faster on big tables: parallel scan — pass
Segment=i, TotalSegments=Nand run N workers (threads/processes), each paginating its own segment. 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.
ProjectionExpressionshrinks the response, not the bill; don't put a scan on a hot path — that's what query and access-pattern design are for. - Items return in DynamoDB JSON (
{"S": ...}). Prefer native Python types? Use the resource API (table.scan+ a manualLastEvaluatedKeyloop — the resource API has no paginator).
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.
Related examples
- Get all items in Node.js — the same full read with an explicit loop.
- Get all items with the AWS CLI — the CLI pages for you.
- DynamoDB Scan in Python — scanning with a
FilterExpression. - Parallel scans — Segment/TotalSegments, worker counts, and when to bother.
- Why is my DynamoDB Scan slow and expensive? — the cost model and how to avoid it.
- DynamoDB ProvisionedThroughputExceededException — reading the whole table is the classic way to hit it.
- "The provided starting key is invalid" — a mangled resume key in the pagination loop.
References
- Scan — Amazon DynamoDB API Reference
- DynamoDB.Paginator.Scan — Boto3 documentation
- Scanning tables in DynamoDB — Amazon DynamoDB Developer Guide
- DynamoDB read and write operations (capacity unit consumption) — Amazon DynamoDB Developer Guide
Last verified 2026-07-13 against the official AWS documentation linked above.