forked from aosfatos/check-up
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstorage.py
More file actions
25 lines (20 loc) · 667 Bytes
/
Copy pathstorage.py
File metadata and controls
25 lines (20 loc) · 667 Bytes
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
import boto3
from decouple import config
def get_client():
try:
client = boto3.client(
"s3",
aws_access_key_id=config("AWS_ACCESS_KEY_ID"),
aws_secret_access_key=config("AWS_SECRET_ACCESS_KEY"),
region_name=config("AWS_S3_REGION_NAME"),
)
except AttributeError:
raise Exception("Credentials not found")
return client
def upload_file(file_path, object_name):
if file_path is None:
return
s3_client = get_client()
bucket = config("AWS_BUCKET_NAME")
response = s3_client.upload_file(file_path, bucket, object_name)
return f"s3://{bucket}/{object_name}"