3
votes

I want to apply a deletion rule to my whole bucket to delete all objects that are older than 2 weeks. But my bucket has certain folders that need to be skipped. So is it possible via S3 lifecycle management to skip certain folders and delete rest of the stuff that is older than 2 weeks?

Here is my current bucket structure

- example-bucket.com
    - folder 1
        - images
            - 1. jpg
        - videos
            - 1.mp4
            - 2.flv
    - folder 2
        - images
            - 1.jpg
    - folder 3
        - videos
            - 1.mp4
    - folder 4 (Should not be deleted)
        - content
        - folders
    - folder 5  
        - images
            - 1. jpg
        - videos
            - 1.mp4
            - 2.flv
    - folder 6 (Should not be deleted)
        - content
        - folders

I want to skip folder 4 and 6 and want to delete stuff in all other folders that are 14 days old.

Can someone tell me if its possible via AWS S3 Lifecycle management?

2

2 Answers

4
votes

Yes you can. Lifecycle Rule supports prefix/tag to filter what you want to apply the rule.
You need to define which you want to delete except others.
Reference:

To apply this lifecycle rule to all objects with a specified name prefix (i.e., objects whose name begins with a common string), type in a prefix. You can also limit the lifecycle rule scope to one or more object tags. You can combine a prefix and tags. For more information about object name prefixes, see Object Keys in the Amazon Simple Storage Service Developer Guide. For more information about object tags, see Object Tagging in the Amazon Simple Storage Service Developer Guide

1
votes

It's really frustrating but it isn't possible without adding every single prefix in the bucket that you want archived or deleted or labelling everything you want deleted, so if you are adding new folders to the bucket you will have to make sure that they conform to the prefix or are tagged which makes a maintenance nightmare. It would be much simpler if you could add an exception tag, particularly if you want a readme in the bucket describing what is in it that isn't archived.