The other questions I could find were refering to an older version of Boto. I would like to download the latest file of an S3 bucket. In the documentation I found that there
If you have a lot of files then you'll need to use pagination as mentioned by helloV. This is how I did it.
get_last_modified = lambda obj: int(obj['LastModified'].strftime('%s'))
s3 = boto3.client('s3')
paginator = s3.get_paginator( "list_objects" )
page_iterator = paginator.paginate( Bucket = "BucketName", Prefix = "Prefix")
for page in page_iterator:
if "Contents" in page:
last_added = [obj['Key'] for obj in sorted( page["Contents"], key=get_last_modified)][-1]