title: AWS Kinesis putRecords in synchronous way using NodeJS SDK
body: <p>I am trying to writ data to Amazon Kinesis using AWS SDK for NodeJS. I am using putRecords method which I want to use with async/await. I need to preform few other steps once the records are written to Kinesis. I want this to be a synchronous process, so I cannot use just callbacks.</p>
  <p>I have tried few different ways using promise, async/await but none of them seem to be working.</p>
  <p>With Async/Await:</p>
  <pre><code>let response = await kinesisPutRecords({ 
      Records: //records,
      StreamName: //streamName
  });
  
  async function kinesisPutRecords(recordsParams){
  
      return new Promise((resolve, reject)=&gt;{
  
          kinesisClient.putRecords(recordsParams,function (err, data) {
              if (err) 
                  reject(err);
              resolve();        
          }
      });
  }
  </code></pre>
  <p>With Promise</p>
  <pre><code>let response = await kinesisClient.putRecords(recordsParams).promise();
  console.log(response);
  
  </code></pre>
  <p>This approaches are used inside a loop, the loop continues without waiting for this call to finish.</p>
  <p>These two approaches work fine with S3.getObject();</p>
  <p>Any help is appreciated. Thank you.</p>
  <h2>Update 1:</h2>
  <p>I found the problem with the above code. Its just missing try...catch block is causing the issue. In my full code, I still have this issue but I was able to find the root cause.</p>
  <p>I am using <a href="https://csv.js.org/transform/" rel="nofollow noreferrer">csv tarnsform</a> with NodeJS streams. Inside the transform function, await is not working. May be because of the fact that stream is async and do not pause?</p>
  <p>Code close to my scenario:</p>
  <pre><code>const transformer = transform(function (record) {
      //add records to an array until a threshold is met and then push to kinesis.
         
  let response = await kinesisPutRecords();
  console.log(response);
      
  }, function(err, output){
    //logic to push remaining records
  });
  
  fileReadStream
     .pipe(gunzip) //unzip the file
     .pipe(csvParser) //to parse the csv
     .pipe(transformer);
  
  
  async function kinesisPutRecords(recordsParams){
  
      return new Promise((resolve, reject)=&gt;{
         try{
             kinesisClient.putRecords(recordsParams,function (err, data) {
                 if (err) 
                    reject(err);
                 resolve();        
             });
         }
         catch(exception ex){
             reject();
         }
      });
  }
  </code></pre>