Aggregated size of all range keys has exceeded the size limit of 1024 bytes
TL;DR — DynamoDB 把排序(range)鍵值限制在 1024 位元組,把分割槽(hash)鍵值限制在 2048 位元組(以 UTF-8 編碼測量)。你的排序索引鍵值越過了 1024 位元組——通常是一個塞得過滿的複合鍵。縮短它、對長的部分做雜湊,或者把大塊移入一個非鍵屬性。
這是什麼意思
ValidationException: One or more parameter values were invalid: Aggregated size of all range keys has exceeded the size limit of 1024 bytes
# on DynamoDB Local you get one combined sentence instead, naming neither key:
ValidationException: Hash primary key values must be under 2048 bytes, and range primary key values must be under 1024 bytes這是一個硬性的鍵大小限制,與 400 KB 的項目限制無關。排序索引鍵的值(以 UTF-8 位元組測量)最多 1024 位元組;分割區索引鍵的值最多 2048 位元組。越過它,寫入就會被以一個 HTTP 400 ValidationException 拒絕——一個在鍵變小之前不可重試的請求錯誤。
為什麼會發生
- 過長的複合排序索引鍵——把許多段連線起來(
ORG#…#PROJECT#…#DOC#…#veryLongTitle…)直到值超過 1024 位元組。 - 把一個大的值編碼進鍵——把完整的 URL、路徑、描述或序列化的二進位制塊放進排序索引鍵。
- 多位元組字元——非 ASCII 文字在 UTF-8 中每個佔 2–4 位元組,因此一個"看起來短"的字串可能超過位元組限制。
- 分割區索引鍵太大——針對 2048 位元組 hash 鍵限制的同一類錯誤。
如何修正
- 把複合鍵裁剪到你實際查詢的那些段;去掉人類可讀的填充物。
- 對長的部分做雜湊——在鍵中儲存一個短的確定性摘要(例如一個截斷的 SHA-256),把完整的值作為一個普通屬性保留。
- 把大塊移出鍵——排序索引鍵應該標識/排序項目,而不是攜帶它的載荷;把長文字放進一個非鍵屬性(它享有 400 KB 的項目預算)。
- 以位元組而非字元測量——UTF-8 編碼並計數,尤其是對非 ASCII 資料。
在 DynoTable 中檢視
將草稿項貼上到 item size calculator 中,並在寫入之前檢查關鍵屬性位元組計數。在 DynoTable 中,使用 ⌘K 開啟表,使用暫存 (⌘S) 建立一個測試項,並確認鍵適合 — 過大的鍵在提交之前會失敗。重新設計複合鍵時,在Query Builder中使用較短的鍵段進行原型查詢。使用 ⌘P 切換設定檔案; 在“設定”→“設定檔案”上測試連線。參見連線 AWS和安裝。
來源
- Supported data types and naming rules(2026-07-13 驗證)
- BatchWriteItem — Amazon DynamoDB API Reference(2026-07-13 驗證)
相關錯誤
- Item size has exceeded the maximum allowed size (400 KB)——整個項目(而不只是鍵)太大。
- The provided key element does not match the schema——一個鍵的型別/形態不匹配。
- 學習:DynamoDB item size limit
參考資料
- Supported data types and naming rules in Amazon DynamoDB — Developer Guide
- BatchWriteItem — Amazon DynamoDB API Reference (key length limits)
- Error handling with DynamoDB — Amazon DynamoDB Developer Guide
最後核實於 2026-07-13,依據上方連結的 AWS 官方文件。