Created
June 3, 2023 18:04
-
-
Save rdemorais/87d5311c720d0e7032619b20a527488f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# console: | |
# export AWS_ACCESS_KEY_ID=AWS_KEY | |
# export AWS_SECRET_ACCESS_KEY=AWS_SECRET | |
from tqdm import tqdm | |
import boto3 | |
import os | |
s3 = boto3.client('s3') | |
s3_bucket = 'bucket_name' | |
cache_dir = 'local_dir' | |
file_names = [] | |
for f in s3.list_objects(Bucket=s3_bucket)['Contents']: | |
file_names.append(f['Key']) | |
for file_name in file_names: | |
local_path = os.path.join(cache_dir, file_name) | |
kwargs = {"Bucket": s3_bucket, "Key": file_name} | |
object_size = s3.head_object(**kwargs)["ContentLength"] | |
with tqdm(total=object_size, unit="B", unit_scale=True, desc=file_name) as pbar: | |
s3.download_file( | |
s3_bucket, | |
file_name, | |
local_path, | |
Callback=lambda bytes_transferred: pbar.update(bytes_transferred) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment