File tree Expand file tree Collapse file tree 1 file changed +21
-6
lines changed Expand file tree Collapse file tree 1 file changed +21
-6
lines changed Original file line number Diff line number Diff line change @@ -284,13 +284,28 @@ def _create_bucket_if_not_exists(self) -> None:
284
284
except ClientError :
285
285
logger .warning ("Bucket %s doesn't exist or you don't have access to it." , bucket_name )
286
286
exists = False
287
- if not exists :
288
- try :
289
- bucket .create (CreateBucketConfiguration = {"LocationConstraint" : region })
287
+ if exists :
288
+ return
290
289
291
- bucket .wait_until_exists ()
292
- logger .info ("Created bucket '%s' in region=%s" , bucket_name , region )
293
- except ClientError as error :
290
+ try :
291
+ bucket .create (CreateBucketConfiguration = {"LocationConstraint" : region })
292
+
293
+ bucket .wait_until_exists ()
294
+ logger .info ("Created bucket '%s' in region=%s" , bucket_name , region )
295
+ except ClientError as error :
296
+ if error .response ["Error" ]["Code" ] == "InvalidLocationConstraint" :
297
+ logger .info ("Specified location-constraint is not valid, trying create without it" )
298
+ try :
299
+ bucket .create ()
300
+
301
+ bucket .wait_until_exists ()
302
+ logger .info ("Created bucket '%s' in region=%s" , bucket_name , region )
303
+ except ClientError as error :
304
+ logger .exception (
305
+ "Couldn't create bucket named '%s' in region=%s." , bucket_name , region
306
+ )
307
+ raise error
308
+ else :
294
309
logger .exception (
295
310
"Couldn't create bucket named '%s' in region=%s." , bucket_name , region
296
311
)
You can’t perform that action at this time.
0 commit comments