title: How to get recently uploaded zip file from s3 bucket when we trigger the lambda using node js
body: <blockquote>
    <p>I am uploading a zip file to s3 bucket,Once I uploaded the zip file,my
    lambda Function will get triggered.</p>
    
    <p>Inside the Lambda Function block,I need to get  the recently uploaded zip file name either based
    on Last Modified date of zip file from S3 bucket or Object Creation date from Lambda
    record event</p>
    
    <p>However it may be ,But I need to get recently uploaded zip file name from s3 bucket.**</p>
  </blockquote>
  
  <p><strong>This is my code</strong></p>
  
  <pre><code>s3.listObjects(params, function (err, data) {
      if (err)
          console.log(err, err.stack); // an error occurred
  
  
      var lastZipfile = null;
      var lastModified = null;
      data.Contents.forEach(function (c) {
          if (c.Key.endsWith('tar.gz')) {
              if (lastModified === null) {
                  lastZipfile = c.Key;
                  lastModified = c.LastModified;
              } else {
                  // Compare the last modified dates
                  if (lastModified &lt;= c.LastModified) {
                      // Track the new latest file
                      lastZipfile = c.Key;
                      lastModified = c.LastModified;
                      //extractData(lastZipfile);
                  }
              }
          }
  
      });
  });
  </code></pre>