How to delete files recursively from an S3 bucket

后端 未结 12 614
不知归路
不知归路 2021-01-29 23:54

I have the following folder structure in S3. Is there a way to recursively remove all files under a certain folder (say foo/bar1 or foo or foo/bar2/1 ..)

         


        
12条回答
  •  我在风中等你
    2021-01-30 00:28

    You might also consider using Amazon S3 Lifecycle to create an expiration for files with the prefix foo/bar1.

    Open the S3 browser console and click a bucket. Then click Properties and then LifeCycle.

    Create an expiration rule for all files with the prefix foo/bar1 and set the date to 1 day since file was created.

    Save and all matching files will be gone within 24 hours.

    Just don't forget to remove the rule after you're done!

    No API calls, no third party libraries, apps or scripts.

    I just deleted several million files this way.

    A screenshot showing the Lifecycle Rule window (note in this shot the Prefix has been left blank, affecting all keys in the bucket):

    enter image description here

提交回复
热议问题