2

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
});
2
  • Ok, what have you tried? Commented Mar 10, 2017 at 10:17
  • @LorenaSalamanca I have updated my question Plz check it Commented Mar 10, 2017 at 10:40

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.