2019-10-20 18:51:09 +02:00
|
|
|
.. Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
2016-05-22 04:03:29 +02:00
|
|
|
|
2019-10-20 18:51:09 +02:00
|
|
|
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0
|
|
|
|
International License (the "License"). You may not use this file except in compliance with the
|
|
|
|
License. A copy of the License is located at http://creativecommons.org/licenses/by-nc-sa/4.0/.
|
2016-05-22 04:03:29 +02:00
|
|
|
|
2019-10-20 18:51:09 +02:00
|
|
|
This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
|
|
|
either express or implied. See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
2016-05-22 04:03:29 +02:00
|
|
|
|
|
|
|
|
2019-10-20 18:51:09 +02:00
|
|
|
###########################
|
2021-09-22 18:34:33 +02:00
|
|
|
File transfer configuration
|
2019-10-20 18:51:09 +02:00
|
|
|
###########################
|
2016-05-22 04:03:29 +02:00
|
|
|
|
2019-10-20 18:51:09 +02:00
|
|
|
When uploading, downloading, or copying a file or S3 object, the AWS SDK for
|
|
|
|
Python automatically manages retries and multipart and non-multipart transfers.
|
2016-05-22 04:03:29 +02:00
|
|
|
|
2019-10-20 18:51:09 +02:00
|
|
|
The management operations are performed by using reasonable default settings
|
|
|
|
that are well-suited for most scenarios. To handle a special case, the default
|
|
|
|
settings can be configured to meet requirements.
|
2016-05-22 04:03:29 +02:00
|
|
|
|
2019-10-20 18:51:09 +02:00
|
|
|
Configuration settings are stored in a
|
|
|
|
:py:class:`boto3.s3.transfer.TransferConfig` object. The object is passed to
|
|
|
|
a transfer method (``upload_file``, ``download_file``, etc.) in the ``Config=``
|
|
|
|
parameter.
|
2016-05-22 04:03:29 +02:00
|
|
|
|
2019-10-20 18:51:09 +02:00
|
|
|
The remaining sections demonstrate how to configure various transfer operations
|
|
|
|
with the ``TransferConfig`` object.
|
2016-11-09 01:23:44 +01:00
|
|
|
|
|
|
|
|
2021-09-22 18:34:33 +02:00
|
|
|
Multipart transfers
|
2019-10-20 18:51:09 +02:00
|
|
|
===================
|
2016-11-09 01:23:44 +01:00
|
|
|
|
2019-10-20 18:51:09 +02:00
|
|
|
Multipart transfers occur when the file size exceeds the value of the
|
|
|
|
``multipart_threshold`` attribute.
|
2016-11-09 01:23:44 +01:00
|
|
|
|
2019-10-20 18:51:09 +02:00
|
|
|
The following example configures an ``upload_file`` transfer to be multipart
|
|
|
|
if the file size is larger than the threshold specified in the
|
|
|
|
``TransferConfig`` object.
|
2016-11-09 01:23:44 +01:00
|
|
|
|
2019-10-20 18:51:09 +02:00
|
|
|
.. code-block:: python
|
2016-11-09 01:23:44 +01:00
|
|
|
|
|
|
|
import boto3
|
|
|
|
from boto3.s3.transfer import TransferConfig
|
|
|
|
|
2019-10-20 18:51:09 +02:00
|
|
|
# Set the desired multipart threshold value (5GB)
|
2016-11-09 01:23:44 +01:00
|
|
|
GB = 1024 ** 3
|
2019-10-20 18:51:09 +02:00
|
|
|
config = TransferConfig(multipart_threshold=5*GB)
|
2016-11-09 01:23:44 +01:00
|
|
|
|
2019-10-20 18:51:09 +02:00
|
|
|
# Perform the transfer
|
2016-11-09 01:23:44 +01:00
|
|
|
s3 = boto3.client('s3')
|
2019-10-20 18:51:09 +02:00
|
|
|
s3.upload_file('FILE_NAME', 'BUCKET_NAME', 'OBJECT_NAME', Config=config)
|
2016-11-09 01:23:44 +01:00
|
|
|
|
|
|
|
|
2021-09-22 18:34:33 +02:00
|
|
|
Concurrent transfer operations
|
2019-10-20 18:51:09 +02:00
|
|
|
==============================
|
2016-05-22 04:03:29 +02:00
|
|
|
|
2019-10-20 18:51:09 +02:00
|
|
|
The maximum number of concurrent S3 API transfer operations can be tuned to
|
|
|
|
adjust for the connection speed. Set the ``max_concurrency`` attribute to
|
|
|
|
increase or decrease bandwidth usage.
|
2016-05-22 04:03:29 +02:00
|
|
|
|
2019-10-20 18:51:09 +02:00
|
|
|
The attribute's default setting is 10. To reduce bandwidth usage, reduce the
|
|
|
|
value; to increase usage, increase it.
|
2018-07-11 07:39:36 +02:00
|
|
|
|
2019-10-20 18:51:09 +02:00
|
|
|
.. code-block:: python
|
2018-07-11 07:39:36 +02:00
|
|
|
|
2019-10-20 18:51:09 +02:00
|
|
|
# To consume less downstream bandwidth, decrease the maximum concurrency
|
|
|
|
config = TransferConfig(max_concurrency=5)
|
2016-05-22 04:03:29 +02:00
|
|
|
|
2019-10-20 18:51:09 +02:00
|
|
|
# Download an S3 object
|
2016-05-22 04:03:29 +02:00
|
|
|
s3 = boto3.client('s3')
|
2019-10-20 18:51:09 +02:00
|
|
|
s3.download_file('BUCKET_NAME', 'OBJECT_NAME', 'FILE_NAME', Config=config)
|
2016-05-22 04:03:29 +02:00
|
|
|
|
|
|
|
|
2019-10-20 18:51:09 +02:00
|
|
|
Threads
|
|
|
|
=======
|
2016-05-22 04:03:29 +02:00
|
|
|
|
2019-10-20 18:51:09 +02:00
|
|
|
Transfer operations use threads to implement concurrency. Thread use can be
|
|
|
|
disabled by setting the ``use_threads`` attribute to ``False.``
|
2016-05-22 04:03:29 +02:00
|
|
|
|
2019-10-20 18:51:09 +02:00
|
|
|
If thread use is disabled, transfer concurrency does not occur. Accordingly,
|
|
|
|
the value of the ``max_concurrency`` attribute is ignored.
|
2016-05-22 04:03:29 +02:00
|
|
|
|
2019-10-20 18:51:09 +02:00
|
|
|
.. code-block:: python
|
2016-05-22 04:03:29 +02:00
|
|
|
|
2019-10-20 18:51:09 +02:00
|
|
|
# Disable thread use/transfer concurrency
|
|
|
|
config = TransferConfig(use_threads=False)
|
2016-05-22 04:03:29 +02:00
|
|
|
|
|
|
|
s3 = boto3.client('s3')
|
2019-10-20 18:51:09 +02:00
|
|
|
s3.download_file('BUCKET_NAME', 'OBJECT_NAME', 'FILE_NAME', Config=config)
|