[ 后端篇 ] 07 - AWS DynamoDB操作错误

  • 使用数据库的batchWrite() API 返回的错误
BatchWriteErr -> { ValidationException: The provided key element does not match the schema
    at Request.extractError (/home/mike/Work/Lambda-JoyAgent/node_modules/[email protected]@aws-sdk/lib/protocol/json.js:51:27)
    at Request.callListeners (/home/mike/Work/Lambda-JoyAgent/node_modules/[email protected]@aws-sdk/lib/sequential_executor.js:106:20)
    at Request.emit (/home/mike/Work/Lambda-JoyAgent/node_modules/[email protected]@aws-sdk/lib/sequential_executor.js:78:10)
    at Request.emit (/home/mike/Work/Lambda-JoyAgent/node_modules/[email protected]@aws-sdk/lib/request.js:683:14)
    at Request.transition (/home/mike/Work/Lambda-JoyAgent/node_modules/[email protected]@aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (/home/mike/Work/Lambda-JoyAgent/node_modules/[email protected]@aws-sdk/lib/state_machine.js:14:12)
    at /home/mike/Work/Lambda-JoyAgent/node_modules/[email protected]@aws-sdk/lib/state_machine.js:26:10
    at Request. (/home/mike/Work/Lambda-JoyAgent/node_modules/[email protected]@aws-sdk/lib/request.js:38:9)
    at Request. (/home/mike/Work/Lambda-JoyAgent/node_modules/[email protected]@aws-sdk/lib/request.js:685:12)
    at Request.callListeners (/home/mike/Work/Lambda-JoyAgent/node_modules/[email protected]@aws-sdk/lib/sequential_executor.js:116:18)
    at Request.emit (/home/mike/Work/Lambda-JoyAgent/node_modules/[email protected]@aws-sdk/lib/sequential_executor.js:78:10)
    at Request.emit (/home/mike/Work/Lambda-JoyAgent/node_modules/[email protected]@aws-sdk/lib/request.js:683:14)
    at Request.transition (/home/mike/Work/Lambda-JoyAgent/node_modules/[email protected]@aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (/home/mike/Work/Lambda-JoyAgent/node_modules/[email protected]@aws-sdk/lib/state_machine.js:14:12)
    at /home/mike/Work/Lambda-JoyAgent/node_modules/[email protected]@aws-sdk/lib/state_machine.js:26:10
    at Request. (/home/mike/Work/Lambda-JoyAgent/node_modules/[email protected]@aws-sdk/lib/request.js:38:9)
    at Request. (/home/mike/Work/Lambda-JoyAgent/node_modules/[email protected]@aws-sdk/lib/request.js:685:12)
    at Request.callListeners (/home/mike/Work/Lambda-JoyAgent/node_modules/[email protected]@aws-sdk/lib/sequential_executor.js:116:18)
    at callNextListener (/home/mike/Work/Lambda-JoyAgent/node_modules/[email protected]@aws-sdk/lib/sequential_executor.js:96:12)
    at IncomingMessage.onEnd (/home/mike/Work/Lambda-JoyAgent/node_modules/[email protected]@aws-sdk/lib/event_listeners.js:299:13)
    at emitNone (events.js:111:20)
    at IncomingMessage.emit (events.js:208:7)
  message: 'The provided key element does not match the schema',
  code: 'ValidationException',
  time: 2019-03-24T08:02:19.474Z,
  requestId: '45KGH3M6THVP80IPUOURNVOT9JVV4KQNSO5AEMVJF66Q9ASUAAJG',
  statusCode: 400,
  retryable: false,
  retryDelay: 32.06653715996766 }

[ 后端篇 ] 07 - AWS DynamoDB操作错误_第1张图片

    BatchWrite = {
        RequestItems: {
            "TestDemo": [{
                PutRequest: {
                    Item: {
                        userID: "xxxxxxxxxxxxxxxxxxxxxxxxxxxx"

                    }
                }
            }]
        }
    };
    doc.batchWrite( BatchWrite,
    (err, data) => {
        if (err) {
            callback(null, { status: "503" });
            return;
        }
    });

操作过程中一直返回 The provided key element does not match the schema,意思为 提供的关键元素与schema不匹配.

仔细的可以发现BatchWrite参数中 userID: “xxxxxxxxxxxxxxxxxxxxxxxxxxxx” 和数据库中参数userld 不一致导致的,跟改为userId: “xxxxxxxxxxxxxxxxxxxxxxxxxxxx”,问题解决。

你可能感兴趣的:([,云端开发,],aws)