Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there an easy way to set up a bucket in s3 to automatically delete files older than x days?

share|improve this question
up vote 7 down vote accepted

Amazon now has the ability to set bucket policies to automatically expire content:

share|improve this answer

Amazon has meanwhile introduced S3 lifecycles (see the introductory blog post Amazon S3 - Object Expiration), where you can specify a maximum age in days for objects in a bucket - see Object Expiration for details on its usage via the S3 API or the AWS Management Console.

share|improve this answer
+1 for providing an update regarding this outdated information, thanks! – Steffen Opel Feb 26 '12 at 16:44

You can use s3cmd to write a script to run through your bucket and delete files based on a precondition.

You'll need to write some code (bash, python) on top of it.

You can download s3cmd from

share|improve this answer

No, S3 is just a datastore. You'll need to use some outside client to periodically delete the old files.

share|improve this answer
This is no longer true:… – Tarrant Oct 9 '12 at 23:44
Ah, that makes things much easier. Although, for my backups I still prefer to perform the deletion from my script, to make sure older backups are only purged when a new one has been made successfully. – Martijn Heemels Oct 15 '12 at 8:34

shell script to delete old buckets using s3cmd utility
source :

# Usage: ./deleteOld "bucketname" "30 days"
s3cmd ls s3://$1 | while read -r line;  do

createDate=`echo $line|awk {'print $1" "$2'}`
createDate=`date -d"$createDate" +%s`
olderThan=`date -d"-$2" +%s`
if [[ $createDate -lt $olderThan ]]
    fileName=`echo $line|awk {'print $4'}`
    echo $fileName
    if [[ $fileName != "" ]]
        s3cmd del "$fileName"
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.