How to download the latest file of an S3 bucket using Boto3?

后端 未结 7 1017
借酒劲吻你
借酒劲吻你 2021-01-11 23:22

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

7条回答
  •  感情败类
    2021-01-12 00:15

    You can do

    import boto3
    
    s3_client = boto3.client('s3')
    response = s3_client.list_objects_v2(Bucket='bucket_name', Prefix='prefix')
    all = response['Contents']        
    latest = max(all, key=lambda x: x['LastModified'])
    

提交回复
热议问题