From a10a900716b9b279e0b564d4287d4ab7fe7bc2d6 Mon Sep 17 00:00:00 2001 From: dzikafoczka Date: Sat, 21 Dec 2024 22:41:51 +0100 Subject: [PATCH] test --- ec2.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ec2.py b/ec2.py index 014b1ed..7bc1da3 100644 --- a/ec2.py +++ b/ec2.py @@ -1,4 +1,5 @@ import boto3 +from boto3.s3.transfer import S3Transfer import base64 import os @@ -270,12 +271,13 @@ def create_s3_bucket(s3_client, bucket_name): return bucket_name def upload_files_to_s3(s3_client, bucket_name, folder_path): + transfer = S3Transfer(s3_client) for root, dirs, files in os.walk(folder_path): for file in files: file_path = os.path.join(root, file) try: - s3_key = os.path.relpath(file_path, folder_path) # Using relative path - s3_client.upload_file(file_path, bucket_name, s3_key) + s3_key = os.path.relpath(file_path, folder_path) + transfer.upload_file(file_path, bucket_name, s3_key) print(f"Uploaded {file} to S3 bucket '{bucket_name}' at key '{s3_key}'.") except Exception as e: print(f"Failed to upload {file} to S3 bucket '{bucket_name}': {str(e)}")