AWS DynamoDB 報錯:The provided key element does not match the schema
在這個坑上,經歷了兩次,所以我不得不寫篇文章記錄一下。起先是因為我只定義了一個 schema:
KeySchema: - AttributeName: id KeyType: HASH
後來,變成了兩個:
KeySchema: - AttributeName: id KeyType: HASH - AttributeName: token KeyType: RANGE
結果在對應的查詢引數的 Key 裡,漏掉了這部分的內容:
Key: { id: body.id },
導致了:
{ ValidationException: The provided key element does not match the schema at Request.extractError (/var/runtime/node_modules/aws-sdk/lib/protocol/json.js:48:27) at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:105:20) at Request.emit (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:77:10) at Request.emit (/var/runtime/node_modules/aws-sdk/lib/request.js:683:14) at Request.transition (/var/runtime/node_modules/aws-sdk/lib/request.js:22:10) at AcceptorStateMachine.runTo (/var/runtime/node_modules/aws-sdk/lib/state_machine.js:14:12) at /var/runtime/node_modules/aws-sdk/lib/state_machine.js:26:10 at Request.<anonymous> (/var/runtime/node_modules/aws-sdk/lib/request.js:38:9) at Request.<anonymous> (/var/runtime/node_modules/aws-sdk/lib/request.js:685:12) at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:115:18) message: 'The provided key element does not match the schema', code: 'ValidationException', time: 2019-02-26T12:31:25.507Z, requestId: 'POTAMPSSPFSOIU78QM637HK7BNVV4KQNSO5AEMVJF66Q9ASUAAJG', statusCode: 400, retryable: false, retryDelay: 44.331159666822884 } null END RequestId: 782c2eb3-629e-43e0-b63c-c66678c5590b
下次,記得,加上,加上:
Key: { id: body.id, token: body.token// 缺少了這部分的內容 },