我有一种 python 方法将本地文件夹中存在的一个文件发送到 S3。我想修改方法将文件夹中存在的所有文件发送到S3。
我的方法是:
import boto3
from boto3 import Session
from botocore.exceptions import NoCredentialsError
session_root = boto3.Session(region_name='eu-west-3', profile_name='my_profile')
s3_client = session_root.client('s3')
prefix_key = "S3_folder/"
local_path = "/home/local_folder/"
bucket_name = "bucket_S3"
def upload_to_aws(local_file, bucket, s3_file):
try:
s3_client.upload_file(local_file, bucket, s3_file)
print("Upload Successful")
return True
except FileNotFoundError:
print("The file was not found")
return False
except NoCredentialsError:
print("Credentials not available")
return False
uploaded_files_to_S3 = upload_to_aws(local_path, bucket_name, prefix_key)
请您知道如何修改它以获取我的
local_folder
中的所有文件并将它们发送到S3_folder
?
谢谢,
您可以通过命令实现此目的
aws s3 cp `your local folder` `s3://bucket`