Ashutosh Rai
Ashutosh Rai

Reputation: 125

Deleting an Amazon S3 object using S3 rule?

We have a use case where we need to delete the files from Amazon S3 after two days.

So lets suppose our bucket name is BucketA and in BucketA we have three folders namely:-

We want to delete all the files inside the bucket except the the folder3.

Can you please how we can achieve this.I tried deletion using S3 rule but it doesnt seem to work

How we can apply the exclusion logic for folder 3.

Thank in advance.

Upvotes: 0

Views: 333

Answers (1)

aherve
aherve

Reputation: 4070

In your s3 bucket you can setup expiration rules. They can be applied by a combination of prefixes, and tags.

That mean that you could either:

  • specify an expiration rule with prefix folder1, and another one with prefix folder2, or
  • use a tag on every files, except for folder3 files. For instance you could add a tag has_ttl:true to all files in folder1 and folder2 and use an expiration rule based on this tag, or
  • apply an expiration rule for the whole bucket, and move your folder3 files to another s3 bucket

As far as I know, it is not possible to write an exclusion rule for expiration policy.

Upvotes: 2

Related Questions