Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can files uploaded to Amazon S3 get auto-deleted after few days?

Tags:

amazon-s3

Amazon S3 API has added Object Expiration which deleted all the files uploaded within a folder after few days.

Is it possible to make the same for each file from the day it was uploaded?

For example when I upload foo.png, after X days, delete that file not all the files within the folder.

like image 890
jQuerybeast Avatar asked Mar 14 '12 08:03

jQuerybeast


1 Answers

Your file path is not more than a prefix in S3. So, if you have a structure as follows:

/  
|  
+--folder1   
    |  
    +--folder2  
    |   
    +--folder3  
    |   |  
    |   +--foo.png  
    |   |  
    |   +--foo2.png  
    |  
    +--bar.png  

And you want your rule to apply only to foo.png, set it to "folder1/folder3/foo.png" (there will be only one file matching the "entire-name" prefix in your bucket).

But be aware of the limits regarding number of rules. From Object Expiration docs:

To set an object’s expiration, you add a lifecycle configuration to your bucket, which describes the lifetime of various objects in your bucket. A lifecycle configuration can have up to 100 rules. Each rule identifies an object prefix and a lifetime for objects that begin with this prefix. The lifetime is the number of days since creation when you want the object removed.

like image 62
Viccari Avatar answered Oct 23 '22 03:10

Viccari