博托+;Python+;AWS S3:如何获取特定文件的上次修改属性?
可以获取上次修改的属性:博托+;Python+;AWS S3:如何获取特定文件的上次修改属性?,python,python-2.7,amazon-web-services,amazon-s3,boto3,Python,Python 2.7,Amazon Web Services,Amazon S3,Boto3,可以获取上次修改的属性: 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 但它对桶中的所有对象都是如此。如何获取bucket下某个特定对象/文件的last\u modified属性 bucket_name = 'bucke
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
但它对桶中的所有对象都是如此。如何获取bucket下某个特定对象/文件的last\u modified
属性
bucket_name = 'bucket-one'
file_name = 'my_file'
object = s3.Object(bucket_name, file_name)
print object.last_modified
或者简单地说:
print s3.Object(bucket_name, file_name).last_modified
希望这能帮助你 这将获得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)
谢谢