Interview Prep/Python for DevOps/boto3 & AWS automation

How do you upload and download S3 objects efficiently?

IntermediateConceptboto3 & AWS automation
Answer

Use the managed transfer methods, which do multipart uploads and parallel parts automatically:

from boto3.s3.transfer import TransferConfig
cfg = TransferConfig(multipart_threshold=64 * 2**20, max_concurrency=10)
s3.upload_file("backup.tar.gz", "acme-backups", "db/2026-11-09.tar.gz", Config=cfg,
               ExtraArgs={"ServerSideEncryption": "aws:kms", "StorageClass": "STANDARD_IA"})
s3.download_file("acme-backups", key, "/tmp/restore.tar.gz")

put_object is a single request limited to 5 GB and has no parallelism. Use list_objects_v2 paginators, not list_objects.

All Python for DevOps questions Roadmap: Python for automation

More on boto3 & AWS automation