S3 Object expiration #1341

Closed
vskr opened this Issue Feb 19, 2013 · 1 comment

Comments

Projects
None yet
2 participants

vskr commented Feb 19, 2013

I was trying to figure out a way to clean up my s3 bucket. I want to delete all the keys that are older than X days ( In my case X is 30 days).

I couldn't figure out a way to delete the objects in s3.

I used the following approaches, none of which worked (By worked, I mean I tried getting the object after X days, and s3 was still serving the object. I was expecting "Object not found" or "Object expired" message

Approach 1:

    k = Key(bucket)
    k.key = my_key_name
    expires = datetime.utcnow() + timedelta(seconds=(10))
    expires = expires.strftime("%a, %d %b %Y %H:%M:%S GMT")
    k.set_contents_from_filename(filename,headers={'Expires':expires})

Approach 2:

    k = Key(bucket)
    k.key = "Event_" + str(key_name) + "_report"
    expires = datetime.utcnow() + timedelta(seconds=(10))
    expires = expires.strftime("%a, %d %b %Y %H:%M:%S GMT")
    k.set_meta_data('Expires', expires)
    k.set_contents_from_filename(filename)

If anyone can share the code that was working for them, which deletes s3 objects, that would be really great

@ghost ghost assigned jamesls Feb 21, 2013

Owner

jamesls commented Feb 22, 2013

Hi, I answered your question on stackoverflow

Could you let me know if that works for you?

@jamesls jamesls closed this Sep 21, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment