Node.js 如果值是重复的DynamoDB,则删除行

Node.js 如果值是重复的DynamoDB,则删除行,node.js,aws-lambda,amazon-dynamodb,Node.js,Aws Lambda,Amazon Dynamodb,我试图比较dynambodb是否有重复的电话号码,如果有,我想删除旧的电话号码。通过lambda这样做似乎没有太多。我们将非常感谢您的帮助。谢谢 const dynamoDb = new AWS.DynamoDB.DocumentClient(); const params = { TableName: process.env.DYNAMODB_TABLE, ProjectionExpression: "phoneNumber, createdAt", }; module.export

我试图比较dynambodb是否有重复的电话号码,如果有,我想删除旧的电话号码。通过lambda这样做似乎没有太多。我们将非常感谢您的帮助。谢谢

const dynamoDb = new AWS.DynamoDB.DocumentClient();
const params = {
  TableName: process.env.DYNAMODB_TABLE,
  ProjectionExpression: "phoneNumber, createdAt",
};

module.exports.list = (event, context, callback) => {
  // fetch all LakeSubscriptions from the database
  dynamoDb.scan(params, (error, result) => {
    // handle potential errors
    if (error) {
      console.error(error);
      callback(null, {
        statusCode: error.statusCode || 501,
        headers: { 'Content-Type': 'text/plain' },
        body: 'Couldn\'t fetch the item.',
      });
      return;
    }
    /*
    for(item in result.phoneNumber){   //not really sure how I can pull these individual values I need to use to compare.

    module.exports.delete = (event, context, callback) => {
  const params = {
    TableName: process.env.DYNAMODB_TABLE,
    Key: {
      id: event.pathParameters.id,
    },
  };

  // delete the lakeSubscription from the database
  dynamoDb.delete(params, (error) => {
    // handle potential errors
    if (error) {
      //error handling
      });
      return;
    }
  });
};
}
*/


    // create a response
    const response = {
      statusCode: 200,
      body: JSON.stringify(result.Items),
    };
    callback(null, response);
  });
};


不是Node.JS方面的专家,但有一些建议

扫描操作结果以每个1MB的页面返回,因此上面的代码不会返回dynamodb中的所有行。请参阅步骤4.3:本文档的扫描

这将使您了解如何分页并从dynamodb获取所有记录。您可以添加所有结果

另请参阅以下帖子

这会给你一个更好的主意