Boto + Python + AWS S3: How to get the last_modified attribute of a specific file?
It can be obtained by the last_modified attribute:
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
But it does this for all objects in the bucket. How can I get the attribute last_modified
for one specific object / file under the bucket?
+3
source to share
2 answers
Hope this helps you ....
This will result in the last modified time of the specific object in the S3 bucket
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)
Thank....
+2
source to share