Amazon S3 – How to delete files older than x days

The following post is a short guide on how to expire Amazon S3 objects by means of defining a simple lifecycle rule. In this tutorial, we’ll be deleting all files in the bucket that are older than 30 days.

  1. Log in to your Amazon S3 console, open S3 bucket you want to have your old files deleted from and click on “Add lifecycle rule”:
  2. Create a new lifecycle rule, call it: cleanup (or something you can easily identify in the future):

  3. Configure Transitions:

  4. Configure Expiration to your own rule. In my case, I am expiring files 30 days after their creation and removing them once for all 1 day later. Or in other words: Removing all files in the bucket that are older than 30 days into the trash, and deleting them permanently a day after they were put into the trash.

  5. Double check the summary to make sure everything is correctly setup and save the new ‘cleanup’ rule:

  6. New ‘cleanup’ rule should be created now: