Automatic deletion of files from S3 bucket

Amazon S3, also known as Amazon Simple Storage Service, is a web service interface-based object storage service provided by Amazon Web Services. Anything we want to store is allowed, including backup files, aws log files, etc.

An earlier post described how to move MySQL backup files to S3 buckets. We’ll look at how to create a simple lifecycle rule in this article to remove such files from Amazon S3. All files in the bucket that are older than 7 days will be destroyed under the rule we’ll create.


  • Log in to your Amazon S3 interface, choose the S3 bucket from which you wish to delete your old data, and select “Management.”


  • Click on Create lifecycle rule under Management.


  • You will see a popup for “Lifecycle rule configuration,” where you must enter the details regarding the rule’s name, scope, actions, etc.
  • Let’s give it a relevant name, such as “Delete files older than a week.” (Review the screenshot provided below)
  • In this example, the rule scope I chose is “Apply to all objects in the bucket.”
  • Check “Expire current versions of items” and “Permanently remove noncurrent versions of objects” under “Life cycle rule actions”. These two rules will help in deleting the current versions and noncurrent versions of objects.
  • Give the number of days that the files need to be retained in the bucket under “Expire current versions of objects” below that. The files that were created earlier than the specified days will be deleted. Provide 6 if you want to keep the files that were created within the last week. Meaning Day 0 to Day 6.
  • Provide the same number of days under “Permanently delete noncurrent versions of objects” if you also want to delete noncurrent versions of objects.
  • You don’t need to supply anything in “Number of newer versions to retain – Optional” after specifying these numbers because the title clearly states that it is optional.
  • That’s it, you can review transition and expiration actions and click “Save”.


You don’t need to do anything else because this rule automatically deletes the files based on the specified conditions.

Hope you find this article useful.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s