-
Notifications
You must be signed in to change notification settings - Fork 0
/
S3Manager.py
35 lines (30 loc) · 1.05 KB
/
S3Manager.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
27
28
29
30
31
32
33
34
35
import boto3
import logging
from botocore.exceptions import ClientError
class S3Manager:
def __init__(self, region=None):
if region is None:
self.client = boto3.client('s3')
else:
self.client = boto3.client('s3', region_name=region)
def createBucket(self, bucketName, region=None):
try:
if region is None:
self.client.create_bucket(Bucket=bucketName)
else:
location = {'LocationConstraint': region}
self.client.create_bucket(Bucket=bucketName,
CreateBucketConfiguration=location)
except ClientError as e:
logging.error(e)
return False
return True
def getBuckets(self):
return self.client.list_buckets()
def uploadFile(self, fileName, bucket, objectName):
try:
response = self.client.upload_file(fileName, bucket, objectName)
except ClientError as e:
logging.error(e)
return False
return True