简体   繁体   中英

aws boto3 s3 put_object error handling/testing

How should errors be handled/tested for 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?

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. Does s3 block as opposed to error when some rate is exceeded?

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?

AWS s3 does not restrict uploads based on requests. 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

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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