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 like to list only objects that were added after the last time I looped through the entire bucket.
I know I can use the Marker
property to start from a certain object name,so I could give it the last object I processed in the text file but that does not guarantee a new object wasn't added before that object name. e.g. if the last file in the text file was oak.txt and a new file called apple.txt was added, it would not pick that up.
s3_resource = boto3.resource('s3')
client = boto3.client('s3')
def list_rasters(bucket):
bucket = s3_resource.Bucket(bucket)
for bucket_obj in bucket.objects.filter(Prefix="testing_folder/"):
print bucket_obj.key
print bucket_obj.last_modified
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…