如何使用Asyncio在S3存储桶上下载文件 [英] How to use asyncio to download files on s3 bucket

查看:117
本文介绍了如何使用Asyncio在S3存储桶上下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码将我的所有文件下载到s3存储桶中:

I'm using the following code to download all my files in a s3 bucket:

def main(bucket_name, destination_dir):
    bucket = boto3.resource('s3').Bucket(bucket_name)
    for obj in bucket.objects.all():
        if obj.key.endswith('/'):
            continue
        destination = '%s/%s' % (bucket_name, obj.key)
        if not os.path.exists(destination):
            os.makedirs(os.path.dirname(destination), exist_ok=True)
        bucket.download_file(obj.key, destination)

如果可能的话,我想知道如何使它异步.

I would like to know how to make this asynchronous, if possible.

预先感谢你.

推荐答案

Aiobotocore 提供了异步使用aiohttp支持botocore库.如果您愿意修改代码以使用 botocore 代替,那将是一个解决方案.

Aiobotocore provides asyncio support for botocore library using aiohttp. If you are willing to modify your code to use botocore instead, that would be a solution.

这篇关于如何使用Asyncio在S3存储桶上下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆