使用Nodejs Lambda函数删除AWS S3对象 [英] Delete AWS S3 Object using Nodejs Lambda function
问题描述
我想根据使用Node.js Lambda函数创建的时间删除AWS S3对象.我想删除24小时之前创建的特定文件夹中的所有对象
现在,我尝试删除成功的多个对象,但是我不知道该如何随着时间进行
I want to delete AWS S3 Object according to the time of creation using Nodejs Lambda function. I want to delete all objects in a particular folder which are created before 24 hour
Now I have tried to delete multiple object which is success but I dnt know how to do it with time
var params = {
Bucket: s3bucket,
Delete: {
Objects: [
{
Key: 'scheduled_lambda_test/1.png'
},
{
Key: 'scheduled_lambda_test/2.png'
}
]
}
};
s3.deleteObjects(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
推荐答案
您可以使用节点sdk并执行以下操作
You can use node sdk and perform below operations
-
在文件夹上使用listObject操作.
use listObject action on your folder.
浏览该文件夹返回的所有对象,并检查上次修改日期.
Loop through all the object returned for that folder and check last modified date.
如果对象过期,则将对象键添加到数组中.
If object is expired add object key to an array.
删除过期数组中的所有对象
Delete all the object in expired array
Node SDK文档- http://docs.aws.amazon .com/AWSJavaScriptSDK/latest/AWS/S3.html
Node SDK Doc - http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html
这篇关于使用Nodejs Lambda函数删除AWS S3对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!