Can files uploaded to Amazon S3 be automatically deleted after a few days?

The Amazon S3 API added Object Expiration, which removed all files uploaded to the folder after a few days.

Is it possible to do the same for every file from the day it was downloaded?

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


source to share

1 answer

Your file path is nothing more than a prefix in S3. So, if you have a structure like this:

    |   |  
    |   +--foo.png  
    |   |  
    |   +--foo2.png  


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

But keep in mind the limits on the number of rules. From Expiry Documents :

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



All Articles