0

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:

  1. campaignId must be equal to the campaignId that I get from query params.
  2. isComplete should be equal to false (Boolean)

The code written above neither give any error nor a success message. Attaching the cloudwatch logs screenshot below : CloudWatch Logs

What am I missing. I looked at a lot of questions and tutorials, but nothing worked for me. Please Help!

  • Might I suggest you add a `return` statement to your `scanIncompleteProcessedCsv()` function? – Jens Dec 17 '20 at 20:28

1 Answers1

0

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

hoangdv
  • 9,655
  • 3
  • 13
  • 34