I've been working on a project involving AWS DynamoDB where I need to query a table for email addresses and determine the number of duplicate emails. However, when I execute the function below, it returns undefined
which has left me puzzled.
let docClient = new AWS.DynamoDB.DocumentClient();
function checkEmail(email) {
var params = {
TableName: "Users",
IndexName: "email",
KeyConditionExpression: "email=:email",
ExpressionAttributeValues: {
":email": email
}
}
var emails = 0;
docClient.query(params, function (err, data) {
if (err) {
return -1;
}
else {
emails = data.ScannedCount;
}
});
return emails;
}
I suspect that the issue lies in the function completing before the table is fully queried. I'm considering using async/await but unsure of how to implement this. Any advice or guidance would be greatly appreciated.