【发布时间】:2017-09-14 00:29:14
【问题描述】:
我正在将 zip 文件上传到 s3 存储桶,一旦我上传了 zip 文件,我的 lambda 函数将被触发。
在 Lambda 函数块中,我需要获取最近上传的 zip 文件名 来自 S3 存储桶的 zip 文件的最后修改日期或来自 Lambda 的对象创建日期 记录事件
不过可能是这样,但我需要从 s3 存储桶中获取最近上传的 zip 文件名。**
这是我的代码
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);
}
}
}
});
});
【问题讨论】:
标签: node.js amazon-s3 aws-lambda