I'm trying to compare if dynambodb has duplicate phoneNumbers and if it does I want to delete the older one. There doesn't seem to be a whole lot, on doing this through lambda. Some help would be appreciated. Thanks
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);
});
};