Boto + Python + AWS S3:如何获取特定文件的last_modified属性?

时间:2017-06-12 23:33:11

标签: python python-2.7 amazon-web-services amazon-s3 boto3

可以获得last_modified属性:

import boto3

s3 = boto3.resource('s3')

bucket_name = 'bucket-one'
bucket = s3.Bucket(bucket_name)

for obj in bucket.objects.all():
    print obj.last_modified

但它适用于存储桶中的所有对象。如何获取存储桶下某个特定对象/文件的last_modified属性?

2 个答案:

答案 0 :(得分:2)

public void setFileSelectionMode(int mode)

或简单地说:

bucket_name = 'bucket-one'
file_name = 'my_file'

object = s3.Object(bucket_name, file_name)
print object.last_modified

答案 1 :(得分:2)

希望这可以帮助你......

这将获得S3存储桶中特定对象的上次修改时间

import boto3
import time
from pprint import pprint

s3 = boto3.resource('s3',region_name='S3_BUCKET_REGION_NAME')
bucket='BUCKET_NAME'
key='OBJECT_NAME'
summaryDetails=s3.ObjectSummary(bucket,key)
timeFormat=summaryDetails.last_modified
formatedTime=timeFormat.strftime("%Y-%m-%d %H:%M:%S")
pprint( 'Bucket name is '+ bucket + ' and key name is ' + key + ' and last modified at time '+ formatedTime)

...谢谢