将dataframe数据直接写到s3

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())
上一篇:aws认证sap考试经验有哪些?aws认证运维人员考察什么?


下一篇:AWS Cloud Front(CDN)清理缓存方法