-
Notifications
You must be signed in to change notification settings - Fork 0
/
s3_client.py
26 lines (21 loc) · 855 Bytes
/
s3_client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import os
import base64
import boto3
S3_CLIENT = boto3.client('s3', region_name=os.environ['AWS_REGION_NAME'],
aws_access_key_id=os.environ['aws_access_key_id'],
aws_secret_access_key=os.environ['aws_secret_access_key'])
def upload_to_s3(data, key):
"""Uploads data to s3
:param bucket: the target bucket
:param data: base64 encoded data
:param key: the file name
"""
return S3_CLIENT.put_object(Bucket=os.environ['AWS_BUCKET'],
Key=key, Body=base64.b64decode(data).decode('utf-8'))
def delete_from_s3(key):
"""Removes a file from an s3 bucket
:param bucket: the target bucket
:param key: the file to be removed
"""
return S3_CLIENT.delete_object(Bucket=os.environ['AWS_BUCKET'],
Key=key)