如果我有一个 CSV 文件存储在特定的本地文件夹中,如何使用 Python 将其上传到 S3 存储桶中的特定文件夹?
import boto3
from datetime import datetime
timestamp = datetime.now().strftime("%Y%m%d_%H%M")
local_path = '/root/my_folder/'
filename = f'file_{timestamp}.csv'
df.to_csv(f{local_path}{filename}', index=False)
s3 = boto3.client('s3')
bucket_name = 'bucket'
folder_name = 'output'
object_name = f'{folder_name}/{filename}'
s3.upload_file(f'{local_path}{filename}', bucket_name, object_name)