I am uploading a zip file to s3 bucket,Once I uploaded the zip file,my lambda Function will get triggered.
Inside the Function block,Then I need to get the recently uploaded zip file name either based on Last Modified date of S3 object or Object Creation date from Lambda record event
However it may be ,But I need to get recently uploaded zip file name from s3 bucket.**
This is my 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 <= c.LastModified) {
// Track the new latest file
lastZipfile = c.Key;
lastModified = c.LastModified;
//extractData(lastZipfile);
}
}
}
});
});
via vishnu
No comments:
Post a Comment