Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Amazon S3 life cycle rule for folder

Tags:

My application uses Amazon S3 to store some files, uploaded by customer. I want to set a rule that automatically should watch for particular folder's content, specifically - to delete files, that were created month ago. Is that possible?

like image 964
dim0_0n Avatar asked Jul 18 '15 23:07

dim0_0n


People also ask

Does S3 lifecycle delete folders?

The subfolders DO get deleted when the retention policy set to: "This rule applies to all objects in the bucket". Hopefully, an option will be added soon to AWS retention policy so that it can be set to no include Folders. Hope this helps !

How do I enable life cycle rules to S3 bucket folders?

Sign in to the AWS Management Console and open the Amazon S3 console at https://console.aws.amazon.com/s3/ . In the Buckets list, choose the name of the bucket that you want to create a lifecycle rule for. Choose the Management tab, and choose Create lifecycle rule. In Lifecycle rule name, enter a name for your rule.

Does S3 lifecycle rules apply to existing objects?

Lifecycle policies apply to both existing and new S3 objects, ensuring that you can optimize storage and maximize cost savings for all current data and any new data placed in S3 without time-consuming manual data review and migration.

Is a folder an object in S3?

Amazon S3 has a flat structure instead of a hierarchy like you would see in a file system. However, for the sake of organizational simplicity, the Amazon S3 console supports the folder concept as a means of grouping objects.


2 Answers

Yes you can set a rule that automatically should watch for particular folder's content, specifically - to delete files, that were created month ago.

For this go to 'lifecycle policy' -> 'Expiration'. In 'Expiration' section set prefix as the path to files that you want to apply your rule.

For example: If I want to apply rule to 'fileA.txt' in folder 'myFolder' in bucket 'myBucket'. Then I should set prefix as 'myFolder/'.

Amazon S3 has a flat structure with no hierarchy like you would see in a typical file system. However, for the sake of organizational simplicity, the Amazon S3 console supports the folder concept as a means of grouping objects. Amazon S3 does this by using key name prefixes for objects.

For more info refer: http://docs.aws.amazon.com/AmazonS3/latest/UG/FolderOperations.html

like image 88
akhi1 Avatar answered Nov 13 '22 05:11

akhi1


Yes. You can setup an S3 lifecycle policy that will make S3 automatically delete all files older than X days: http://docs.aws.amazon.com/AmazonS3/latest/dev/ObjectExpiration.html

like image 24
Mircea Avatar answered Nov 13 '22 06:11

Mircea