Provided list of item keys contains duplicates (BatchGetItem)
TL;DR — Your BatchGetItem Keys array for one table lists the same primary key more than once. DynamoDB requires every key in a batch to be unique and rejects the entire request — it doesn't silently drop the dupe. De-duplicate the key list before you send it.
What it means
ValidationException: Provided list of item keys contains duplicatesBatchGetItem reads up to 100 items across tables. Within a single table's Keys list, each entry must be a distinct primary key (partition key, or partition + sort key for composite tables). Two entries that resolve to the same key trip this HTTP 400 ValidationException, and the whole call fails — no items are returned. It's not retryable as-is.
Why it happens
- The same key appears twice in the list — often because IDs were collected from multiple sources and never merged.
- A generated key list (e.g. mapping a list of records to keys) where the source had duplicate rows.
- Composite-key confusion — two entries share the partition key but you forgot the sort key differs; or both are genuinely identical.
- Case / type differences masking a real duplicate — two keys that marshal to the same value.
- Loading pipelines (Glue, custom ETL) that batch keys without a de-dupe step.
How to fix it
- De-duplicate before the call. Key each entry by a stable string and keep one:
const seen = new Set(); const keys = raw.filter((k) => { const id = `${k.pk.S}#${k.sk?.S ?? ''}`; if (seen.has(id)) return false; seen.add(id); return true; }); - Remember a batch is a set, not a bag — you only ever need one read per key; the item comes back once regardless.
- Chunk to 100 keys per
BatchGetItemand handleUnprocessedKeysin the response (throttling, not duplicates). - Guard your ETL/loader with the same de-dupe so the problem can't recur upstream.
- Log the key list length before each batch. When duplicates slip in, the error gives no index — your logs must show which upstream source repeated an ID.
Path in DynoTable
Before you batch-read keys from production, spot duplicates in DynoTable — open the table with ⌘K, filter to the IDs you plan to fetch, and confirm each primary key appears once. The item list shows partition and sort keys side by side so composite-key collisions are obvious.
When you move the read into code, use the Query Builder to prototype single-key reads first, then scale to chunked BatchGetItem. Switch profiles with ⌘P; configure them under Settings → Profiles with Test Connection. See Connect to AWS and Install.
Sources
- BatchGetItem — Amazon DynamoDB API Reference (verified 2026-07-13)
- Error handling with DynamoDB (verified 2026-07-13)
Related errors
- Provided list of item keys contains duplicates (BatchWriteItem) — the same rule on the write path.
- ValidationException (overview)
- Code example: BatchGetItem in Node.js — a correct chunked batch read to adapt.
- Learn: Batch operations
References
- BatchGetItem — Amazon DynamoDB API Reference
- BatchWriteItem — Amazon DynamoDB API Reference
- Error handling with DynamoDB — Amazon DynamoDB Developer Guide
Last verified 2026-07-13 against the official AWS documentation linked above.