test
This commit is contained in:
parent
d217b55796
commit
a10a900716
6
ec2.py
6
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)}")
|
||||
|
Loading…
Reference in New Issue
Block a user