问题描述
我想从我的s3存储桶中列出对象。 下面的代码没有多线程,因此需要花费大量时间进行处理。 如何在代码中实现多线程
import json
import boto3
def lambda_handler(event,context):
region = ""
bucket_names = test1,test2
s3 = boto3.resource("s3",region_name=region)
unsorted = []
for bucket_name in bucket_names.split(","):
my_bucket = s3.Bucket(bucket_name)
for file in my_bucket.objects.all():
unsorted.append(file)
unsorted.sort(key=lambda x: x.last_modified,reverse=True)
objects = (
{'bucket_name': file.bucket_name,'key': file.key,'last_modified': file.last_modified.strftime("%Y-%m-%dT%H:%M:%s%z"),'size': file.size}
for file in unsorted
)
print(*objects,sep='\n')
```
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)