Skip to content

About

High-throughput S3 folder transfer between two buckets, across different AWS accounts if needed, using SSO profiles and parallel streaming — no disk I/O.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

s3_parallel_transfer.py

High-throughput S3 folder transfer between two buckets, across different AWS accounts if needed, using SSO profiles and parallel streaming — no disk I/O.

Features

  • ✅ Transfers entire S3 folders between different AWS accounts/sessions
  • ✅ Uses named AWS SSO profiles — no hardcoded credentials
  • ✅ Parallel file transfers via ThreadPoolExecutor
  • ✅ Multipart upload/download for large files
  • ✅ Pure in-memory streaming — never writes to disk
  • ✅ Real-time progress reporting
  • ✅ Handles failures per-file without stopping the whole transfer

Requirements

pip install boto3

You also need the AWS CLI installed and configured with SSO profiles.

AWS SSO Setup

Make sure your ~/.aws/config has the profiles configured, for example:

[profile my-source-profile]
sso_start_url = https://your-sso-url.awsapps.com/start
sso_region = eu-west-1
sso_account_id = 111111111111
sso_role_name = PowerUserAccess
region = eu-west-1

[profile my-dest-profile]
sso_start_url = https://your-sso-url.awsapps.com/start
sso_region = eu-west-1
sso_account_id = 222222222222
sso_role_name = PowerUserAccess
region = eu-west-1

Before running the script, authenticate both profiles:

aws sso login --profile my-source-profile
aws sso login --profile my-dest-profile

Note: SSO tokens expire after a few hours. If you see a KeyError on a token hash, just re-run the login commands above and restart the script.

Usage

from s3_parallel_transfer import download_and_upload_s3

download_and_upload_s3(
    bucket_source="my-source-bucket",
    key_prefix_source="folder/to/copy/",
    bucket_dest="my-dest-bucket",
    key_prefix_dest="destination/folder/",
    source_profile="my-source-profile",
    dest_profile="my-dest-profile",
    max_workers=20,  # increase for faster transfers on good networks
)

Parameters

Parameter Type Description
bucket_source str Source S3 bucket name
key_prefix_source str Source folder prefix (e.g. data/input/)
bucket_dest str Destination S3 bucket name
key_prefix_dest str Destination folder prefix (e.g. data/output/)
source_profile str AWS SSO profile name for the source account
dest_profile str AWS SSO profile name for the destination account
max_workers int Number of parallel file transfers (default: 20)

Tuning for Performance

Scenario Recommendation
Fast network / EC2 instance Increase max_workers to 50–100
Many small files Lower multipart_chunksize to 8 MB
Very large files (10GB+) Increase multipart_chunksize to 32 MB
Best possible speed Run on EC2 in the same region as your buckets

Common Errors

Error Cause Fix
ProfileNotFound Profile name is wrong or passed as a tuple Check aws configure list-profiles and ensure you pass a plain string
KeyError: <token hash> SSO token expired or corrupted Run aws sso login --profile <name> again; clear ~/.aws/sso/cache if needed
I/O operation on closed file Buffer shared across threads Fixed in current version — each worker owns its own buffer

| NoCredentialsError | Not logged in via SSO | Run aws sso login --profile <name> |

About

High-throughput S3 folder transfer between two buckets, across different AWS accounts if needed, using SSO profiles and parallel streaming — no disk I/O.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages