Delete AWS S3 Object using Nodejs Lambda function

寵の児 提交于 2020-01-24 19:44:26

问题


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
});

回答1:


You can use node sdk and perform below operations

  1. use listObject action on your folder.

  2. Loop through all the object returned for that folder and check last modified date.

  3. If object is expired add object key to an array.

  4. Delete all the object in expired array

Node SDK Doc - http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html



来源:https://stackoverflow.com/questions/42715682/delete-aws-s3-object-using-nodejs-lambda-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!