Blog

Blog

PHODAL

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  // 缺少了这部分的内容
  },

关于我

Github: @phodal     微博:@phodal     知乎:@phodal    

微信公众号(Phodal)

围观我的Github Idea墙, 也许,你会遇到心仪的项目

QQ技术交流群: 321689806
comment

Feeds

RSS / Atom

最近文章

关于作者

Phodal Huang

Engineer, Consultant, Writer, Designer

ThoughtWorks 技术专家

工程师 / 咨询师 / 作家 / 设计学徒

开源深度爱好者

出版有《前端架构:从入门到微前端》、《自己动手设计物联网》、《全栈应用开发:精益实践》

联系我: h@phodal.com

微信公众号: 最新技术分享

标签