简体   繁体   English

aws boto3 s3 put_object 错误处理/测试

[英]aws boto3 s3 put_object error handling/testing

How should errors be handled/tested for python AWS boto3 s3 put_object?应如何处理/测试 python AWS boto3 s3 put_object 的错误? For example:例如:

import boto3

s3 = boto3.resource('s3')
bucket = s3.Bucket('foo')
bucket.put_object(Key='bar', Body='foobar')

Are the errors that can arise documented somewhere?可能出现的错误是否记录在某处? Is the following even the right documentation page (it seems to be for boto3.client('s3') client, not boto3.resource('s3') ), and if so where are the errors documented?以下甚至是正确的文档页面(它似乎是用于boto3.client('s3')客户端,而不是boto3.resource('s3') ),如果是这样,错误记录在哪里?

http://boto3.readthedocs.io/en/latest/reference/services/s3.html#S3.Client.put_object http://boto3.readthedocs.io/en/latest/reference/services/s3.html#S3.Client.put_object

Simple errors like a non-existent bucket seems easy enough to test, but can spurious errors occur and if so how can that kind of error handling be tested?像不存在的存储桶这样的简单错误似乎很容易测试,但是否会发生虚假错误,如果是这样,如何测试这种错误处理? Are there limits to the upload rate?上传速度有限制吗? I tried the following and was surprised to see all 10000 files successfully created after about 2 minutes of running.我尝试了以下操作,并惊讶地看到在运行大约 2 分钟后成功创建了所有 10000 个文件。 Does s3 block as opposed to error when some rate is exceeded?当超过某个速率时,s3 是否会阻塞而不是错误?

from concurrent.futures import ThreadPoolExecutor

import boto3

s3 = boto3.resource('s3')
bucket = s3.Bucket('foo')

def put(i):
    bucket.put_object(Key='bar/%d' % i, Body='foobar')

executor = ThreadPoolExecutor(max_workers=1024)

for i in range(10000):
    executor.submit(put, i)

Is it good practice to retry the put_object call 1 or more times if some error occurs?如果发生某些错误,重试put_object调用 1 次或多次是一种好习惯吗?

AWS s3 does not restrict uploads based on requests. AWS s3 不限制基于请求的上传。 The restriction is only for size: For Example: 1 POST request will upload files upto 5GB 2 PUT can upload upto 160 GB of size限制仅适用于大小:例如:1 POST 请求将上传最大 5GB 的文件 2 PUT 最多可上传 160 GB 的大小

The errors you are trying or expecting to handle are nothing but client/browser restriction while uploading multiple files at a time.您尝试或期望处理的错误只不过是一次上传多个文件时的客户端/浏览器限制。

Boto3 Upload interface do have parameter called 'config', in which u can specify concurrent uploads: # To consume less downstream bandwidth, decrease the maximum concurrency config = TransferConfig(max_concurrency=5) Boto3 上传接口确实有一个名为“config”的参数,您可以在其中指定并发上传: # 为了消耗更少的下行带宽,降低最大并发 config = TransferConfig(max_concurrency=5)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM