Is there a way to filter s3 objects by last modified date in boto3? I\'ve constructed a large text file list of all the contents in a bucket. Some time has passed and I\'d l
The following code snippet gets all objects under specific folder and check if the file last modified is created after the time you specify :
Replace YEAR,MONTH, DAY
with your values.
import boto3
import datetime
#bucket Name
bucket_name = 'BUCKET NAME'
#folder Name
folder_name = 'FOLDER NAME'
#bucket Resource
s3 = boto3.resource('s3')
bucket = s3.Bucket(bucket_name)
def lambda_handler(event, context):
for file in bucket.objects.filter(Prefix= folder_name):
#compare dates
if (file.last_modified).replace(tzinfo = None) > datetime.datetime(YEAR,MONTH, DAY,tzinfo = None):
#print results
print('File Name: %s ---- Date: %s' % (file.key,file.last_modified))