Procházet zdrojové kódy

Create bucket if does not already exist

DricomDragon před 4 roky
rodič
revize
2fbcb1354a
1 změnil soubory, kde provedl 6 přidání a 2 odebrání
  1. 6 2
      boto-updater.py

+ 6 - 2
boto-updater.py

@@ -1,4 +1,5 @@
 import boto3
+from botocore.exceptions import ClientError
 import os.path
 
 # Arguments
@@ -8,8 +9,11 @@ bucket_target = 'my-bucket'
 # Create connection
 s3 = boto3.client('s3', use_ssl=False, endpoint_url="http://172.17.0.2:9000", aws_access_key_id="minio", aws_secret_access_key="miniokey")
 
-# Reset bucket
-
+# Check bucket
+try:
+    s3.head_bucket(Bucket=bucket_target)
+except ClientError as e:
+    s3.create_bucket(Bucket=bucket_target)
 
 # Get file list
 # Source : https://stackoverflow.com/questions/3207219/how-do-i-list-all-files-of-a-directory