我正在处理的项目涉及下载大型s3存储桶,因此我开始使用Boto3中的paginator功能。当我只使用这个分页器打印存储桶中的所有键时,它会打印所有这些键。但是,当我尝试做更多并使用client.download_file
(也来自Boto3)下载时,它会在中途停止并跳转到我必须下载的下一个存储桶。事情开始变得奇怪,因为当我尝试对这个桶进行分页并下载其密钥时,它甚至不会下载一个密钥,而是跳转到下一个桶。可能是什么问题?
代码:
# This is going to go through and fill in the dictionary with keys from the buckets as specified above
paginator = client.get_paginator("list_objects")
page_iterator = paginator.paginate(Bucket=bucket["Name"])
for i in page_iterator:
c = i["Contents"]
for j in c:
print(j["Key"])
name = file_name_helper(j["Key"])
download(bucket["Name"], j["Key"], "Desktop/S3_Scrubber/" + file_name_helper(j["Key"]), client)
file_name_helper
只是一个将其命名为其他内容的函数,所以它不应该是这个,这是下载函数:
# This will download and delete a file from S3 so we can now have it locally
def download (bucket_name, key, path, client):
key_name = key
print("Dowloading %s..." % str(key))
client.download_file(bucket_name, key, path)
print("Download of %s complete!" % str(key))
return key_name