from boto3.session import Session
import boto3
import os
from io import StringIO
class S3Connect(object):
def __init__(self):
self.aws_key = config.AWS_KEY
self.aws_secret = config.AWS_SECRET
self.bucket = config.AWS_BUCKET
self.session = Session(aws_access_key_id=self.aws_key, aws_secret_access_key=self.aws_secret)
# 将dataframe直接写到s3
def save_df_to_s3(self, df, csv_path):
csv_buffer = StringIO()
df.to_csv(csv_buffer, index=False)
s3_resource = boto3.resource('s3')
s3_resource.Object(self.bucket, csv_path).put(Body=csv_buffer.getvalue())