"""Manual Adjustment s3 file operation logic.""" import boto3 from manualadjustment import config from manualadjustment.ma_timing import timed_fn @timed_fn def upload_to_s3(attachment, key_path, is_stream=False): """PUT local file to AWS S3. Args: attachment (file): file handle key_path (string): path on S3 Returns: (Boolean): Success of upload """ s3 = boto3.resource('s3') if is_stream: s3.Object(config.bucket_name, key_path).put(Body=attachment) else: s3.Object(config.bucket_name, key_path).put(Body=attachment.read()) @timed_fn def delete_from_s3(key_path): """Remove file from S3. Args: key_path (string): path on S3 Returns: (Boolean): Success of delete """ boto_conn = boto3.resource('s3') boto_conn.Object(config.bucket_name, key_path).delete()