简体   繁体   English

在Python中使用boto3从Amazon S3下载最新上传的文件

[英]Download latest uploaded file from amazon s3 using boto3 in python

I have few csv files inside one of my buckets on amazon s3. buckets on amazon s3.一个buckets on amazon s3. few csv files inside buckets on amazon s3.

I need to download the latest uploaded csv file. 我需要download the latest uploaded csv file.

How to achieve this using boto3 in python?? 如何boto3 in python??使用boto3 in python??实现此boto3 in python??

Thanks. 谢谢。

S3 doesn't have an API for listing files ordered by date However, if you indeed have only a few, you can list the files in the bucket and order them by last modification time. S3没有用于按日期列出文件的API。但是,如果确实只有几个,则可以列出存储桶中的文件并按上次修改时间对其进行排序。

bucketList = s3Client.list_objects(Bucket=<MyBucket>) # notice this is up to 1000 files
orderedList = sorted(bucketList, key=lambda k: k.last_modified)
lastUpdatedKey = orderedList[-1]
object = s3Client.get_object(Bucket=<MyBucket>, Key=lastUpdatedKey )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM