Reputation: 25
AWS Documentation Sucks, I can't seem to get an idea of how to "scan" DynamoDb with two or more where conditions, in NodeJS ?
Here's my code
const AWS = require("aws-sdk");
let documentClient = new AWS.DynamoDB.DocumentClient();
module.exports.RetryIncompleteCSV = async (event, context, callback) => {
console.log('In RetryIncompleteCSV');
const cmpId = event.queryStringParameters.campaign;
console.log('cmpId = ', cmpId);
var params = {
TableName : 'processed_csv_developments',
FilterExpression : 'campaignId = :campaignId',
ExpressionAttributeValues : {':campaignId' : cmpId}
};
let incompleteCsvData = await scanIncompleteProcessedCsv(params);
console.log('incompleteCsvData = ', incompleteCsvData);
}
async function scanIncompleteProcessedCsv(params) { // get method fetch data from dynamodb
console.log(params)
const queryExecute = await documentClient.scan(params, function(err, data) {
if (err) console.log(err);
else console.log(data);
console.log('queryExecute=',queryExecute)
});
}
I need scan to filter out data, based on following two conditions:
The code written above neither give any error nor a success message. Attaching the cloudwatch logs screenshot below :
What am I missing. I looked at a lot of questions and tutorials, but nothing worked for me. Please Help!
Upvotes: 0
Views: 373
Reputation: 16127
scanIncompleteProcessedCsv
should return a promise. Now it returns void
, this mean RetryIncompleteCSV
function will finish before a querying to dynamoDB complete.
async function scanIncompleteProcessedCsv(params) { // get method fetch data from dynamodb
console.log(params)
return await documentClient.scan(params).promise();
}
About multiple conditions
, I found to many documents about that, just try:
var params = {
TableName : 'processed_csv_developments',
FilterExpression : 'campaignId = :campaignId AND isComplete = false',
ExpressionAttributeValues : {':campaignId' : cmpId}
};
Ref: Link
Upvotes: 1