Skip to content

Commit 67512fc

Browse files
committed
Fallback to trying to create bucket without LocationConstraint
1 parent c1c13ba commit 67512fc

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/backups.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -284,13 +284,28 @@ def _create_bucket_if_not_exists(self) -> None:
284284
except ClientError:
285285
logger.warning("Bucket %s doesn't exist or you don't have access to it.", bucket_name)
286286
exists = False
287-
if not exists:
288-
try:
289-
bucket.create(CreateBucketConfiguration={"LocationConstraint": region})
287+
if exists:
288+
return
290289

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:
294309
logger.exception(
295310
"Couldn't create bucket named '%s' in region=%s.", bucket_name, region
296311
)

0 commit comments

Comments
 (0)