-
Notifications
You must be signed in to change notification settings - Fork 13
/
s3-helper.py
42 lines (34 loc) · 1.26 KB
/
s3-helper.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
36
37
38
39
40
41
42
import boto3, botocore, argparse, sys, json
from os.path import basename
parser = argparse.ArgumentParser(description='create s3 bucket')
parser.add_argument('-c', '--create', action='store_true', help='create s3 bucket for vidoe face rek')
parser.add_argument('-d', '--delete', action='store_true', help='delete s3 bucket for vidoe face rek')
def createBucket(bucketName, region):
response = client.create_bucket(
ACL='private',
Bucket=bucketName)
print(response)
def deleteBucket(bucketName):
response = client.delete_bucket(
Bucket=bucketName
)
print(response)
def putObject(fileName, bucketName, name):
# Upload a new file
data = open(fileName, 'rb')
tagging = "name=" + name;
client.put_object(Bucket=bucketName, Key=basename(fileNmae), Body=data, Tagging=tagging)
if __name__ == '__main__':
if len(sys.argv)==1:
parser.print_help()
sys.exit(1)
args = parser.parse_args()
with open('config.json') as json_data_file:
config = json.load(json_data_file)
region = config['region']
bucketName = config['bucketName']
client = boto3.client('s3', region_name=region)
if (args.create):
createBucket(bucketName, region)
elif (args.delete):
deleteBucket(bucketName)