“The provided key element does not match the schema” error when getting an item from DynamoDB

前端 未结 3 1530
刺人心
刺人心 2020-12-24 01:23

This is the table partition key setting

The table content

When I tried to get an item from the table, it prints this error

botocore

3条回答
  •  一整个雨季
    2020-12-24 02:03

    I guess you don't have to put all the related attributes

    in my case I only have one PK as col

    const AWS = require('aws-sdk');
    const ddb = new AWS.DynamoDB.DocumentClient();
    
    exports.handler = (event, context, callback) => {
      const connectionId = event.requestContext.connectionId;
      deleteConnectionId(connectionId).then(() => {
        callback(null, { statusCode: 200 , message: 'userId deleted'});
      });
    };
    
    
    function deleteConnectionId(connectionId) {
      return ddb
        .delete({ TableName: 'your table name', 
            Key: {
                userId : connectionId.toString() // userId is my PK in this case
             }
        } )
        .promise();
    }
    

提交回复
热议问题