0

我正在尝试比较 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);
  });
};

4

1 回答 1

1

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

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

https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GettingStarted.NodeJs.04.html

这会给你一些关于如何分页和从 dynamodb 获取所有记录的想法。您可以添加所有结果

另请参阅以下帖子

如何使用 node.js 从`AWS dynamodb` 获取/扫描所有项目

这应该给你更好的主意

于 2019-09-14T00:38:25.263 回答