def upload_file(self, fn):
'''Upload log file to s3'''
target = fn + '.gz'
s3_client = boto3.client('s3')
try:
with open(fn, 'rb') as f_in, gzip.open(target, 'wb') as f_out:
shutil.copyfileobj(f_in, f_out)
with open(target, 'rb') as fd:
s3_client.put_object(
Body=fd,
Bucket=self.bucket,
Key=self.prefix + '/' + os.path.basename(target))
finally:
if os.path.exists(target):
os.remove(target)
评论列表
文章目录