使用boto一次性读取S3路径中所有文件的内容

时间:2021-07-01 22:38:07

Using boto3, I can read the content of a file stored in S3 via

使用boto3,我可以通过读取存储在S3中的文件的内容

s3 = boto3.resource('s3')
s3.Object(bucket_name, path).get()['Body'].read()

I have multiple files in the same path ("directory") and I'd like to read them all building a global data variable storing their comprehensive content (say a dictionary or list).

我在同一个路径(“目录”)中有多个文件,我想读它们所有构建一个存储其综合内容(比如字典或列表)的全局数据变量。

Is there a way to accomplish this from boto without having to read them one by one and concatenate the bodies?

有没有办法从boto完成这个,而不必逐个阅读它们并连接它们的身体?

1 个解决方案

#1


1  

No, there is nothing in the S3 API that supports reading multiple objects in a single API call. You could spin up multiple threads with each retrieving an object to get better throughput.

不,S3 API中没有任何内容支持在单个API调用中读取多个对象。您可以在检索对象时启动多个线程以获得更好的吞吐量。

#1


1  

No, there is nothing in the S3 API that supports reading multiple objects in a single API call. You could spin up multiple threads with each retrieving an object to get better throughput.

不,S3 API中没有任何内容支持在单个API调用中读取多个对象。您可以在检索对象时启动多个线程以获得更好的吞吐量。