Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python boto3从s3 bucket中获取最后一个但只有一个修改过的对象_Python_Amazon Web Services_Amazon S3 - Fatal编程技术网

python boto3从s3 bucket中获取最后一个但只有一个修改过的对象

python boto3从s3 bucket中获取最后一个但只有一个修改过的对象,python,amazon-web-services,amazon-s3,Python,Amazon Web Services,Amazon S3,我有一个用例,我需要列出s3 bucket中最后一个但只有一个修改过的对象,该bucket在s3中有数百万个文件,下面使用boto3 s3客户端过滤是更好的方法吗?这是可行的方法还是最佳实践 这是我s3桶里的东西 s3://mybucket/dataset/date-20210304.txt->lastmodified 2021年3月4日 s3://mybucket/dataset/date-20210303.txt->lastmodified 2021年3月3日 s3://mybucket/d

我有一个用例,我需要列出s3 bucket中最后一个但只有一个修改过的对象,该bucket在s3中有数百万个文件,下面使用boto3 s3客户端过滤是更好的方法吗?这是可行的方法还是最佳实践

这是我s3桶里的东西

s3://mybucket/dataset/date-20210304.txt->lastmodified 2021年3月4日

s3://mybucket/dataset/date-20210303.txt->lastmodified 2021年3月3日

s3://mybucket/dataset/date-20210302.txt->lastmodified 2021年3月2日

我需要取出这个对象->s3://mybucket/dataset/date-20210303.txt

我已经尝试了下面的代码

s3 = boto3.resource('s3')
my_bucket = s3.Bucket("myBucket")
files = my_bucket.objects.filter(Prefix = "dataset/date-")
files = [obj.key for obj in sorted(files, key=lambda x: x.last_modified, 
    reverse=True)]
print("files "+files[1])

我无法从这里打印上次修改的,我在这里做错了什么,有人能帮我吗?

这应该可以解决问题