The table does not have the specified index
TL;DR — 你 Query/Scan 中的 IndexName 在那張表上(從這個用戶端的區域 + 帳戶看)不存在、拼寫錯誤,或者該 GSI 仍在 CREATING 且還不可查詢。用 DescribeTable 確認確切的索引名稱和狀態,然後修復呼叫。
這是什麼意思
ValidationException: The table does not have the specified index: <IndexName>
# what the engine actually returns, reproduced against DynamoDB Local:
ValidationException: The table does not have the specified index: no-such-index你讓 DynamoDB 按名稱 Query 或 Scan 一個特定的次要索引,而表(在這個用戶端看來)沒有一個處於可用狀態的同名索引。它是一個 HTTP 400 ValidationException——屬於用戶端錯誤,在名稱/狀態正確之前不可重試。
為什麼會發生
- 拼寫錯誤或大小寫錯誤——索引名稱區分大小寫;
GSI1≠gsi1。 - 索引屬於另一張表——你從另一張表的模式複製了
IndexName。 - GSI 還未
ACTIVE——一個新建立的全域次要索引在其狀態從CREATING → ACTIVE之前無法查詢(它會先回填)。 - 區域/帳戶錯誤——用戶端指向了一個表(或其索引)不存在的區域(與缺失的表相同的對齊問題)。
- DynamoDB Local 偏差——一個早於該索引的陳舊本地
shared-local-instance.db;重新建立它。
如何修正
- 列出真實的索引名稱和狀態:
aws dynamodb describe-table --table-name <Table> \ --query "Table.GlobalSecondaryIndexes[].{Name:IndexName,Status:IndexStatus}" - 把名稱逐字複製進
IndexName——精確匹配大小寫。 - 等待
ACTIVE。 如果 GSI 處於CREATING,查詢只有在回填完成後才有效(DescribeTable會顯示IndexStatus)。 - 用
aws sts get-caller-identity確認區域 + 帳戶,並固定用戶端的region。 - 在 DynamoDB Local 上,刪除本地 db 檔案並重新執行你的表/索引設定,使索引在本地存在。
在多張表和索引之間工作?DynoTable 的資料表對話方塊會列出每張表的 GSI 及其狀態,讓你能挑一個確實存在——且處於 ACTIVE——的索引,而不是猜名稱。當你需要的索引確實不存在時,它也能建立和刪除 GSI。
在 DynoTable 中查詢
使用 ⌘K 開啟 DynoTable 中的表並展開 索引 面板 - 每個 GSI 名稱和 IndexStatus 都會在沒有 CLI 呼叫的情況下列出。從查詢面板的下拉選單中選擇索引,而不是手動輸入 IndexName; DynoTable 僅提供連線表上存在的索引。如果GSI仍然是CREATING,則從側邊欄重新整理表後設資料,直到狀態翻轉到ACTIVE。使用 Query Builder 組成 GSI 查詢並將生成的 IndexName 複製到你的 SDK 程式碼中。當索引存在於一個區域而不是另一個區域時,使用 ⌘P 切換設定檔案。設定:連線 AWS、安裝。
來源
- Managing Global Secondary Indexes in DynamoDB(2026-07-13 驗證)
- Query — Amazon DynamoDB API Reference(2026-07-13 驗證)
相關錯誤
- ResourceNotFoundException——整張表(而不只是一個索引)都找不到。
- Query key condition not supported——索引存在,但你的鍵條件對它是錯的。
- 程式碼示例:Query a GSI in Node.js——IndexName 連線正確。
- 學習:GSI vs LSI · GSIs are eventually consistent · 索引
參考資料
- Managing Global Secondary Indexes in DynamoDB — Amazon DynamoDB Developer Guide
- Query — Amazon DynamoDB API Reference
- Error handling with DynamoDB — Amazon DynamoDB Developer Guide
最後核實於 2026-07-13,依據上方連結的 AWS 官方文件。