Getting S3 objects' last modified datetimes with boto

vreal picture vreal · Mar 13, 2012 · Viewed 57.9k times · Source

I'm writing a Python script that uploads files to S3 using Boto. I only want to upload changed files (which I can check by their "last modified" datetimes), but I can't find the Boto API endpoint to get the last modified date.

Answer

garnaat picture garnaat · Mar 13, 2012

Here's a snippet of Python/boto code that will print the last_modified attribute of all keys in a bucket:

>>> import boto
>>> s3 = boto.connect_s3()
>>> bucket = s3.lookup('mybucket')
>>> for key in bucket:
       print key.name, key.size, key.last_modified
index.html 13738 2012-03-13T03:54:07.000Z
markdown.css 5991 2012-03-06T18:32:43.000Z
>>>