Skip to content

Commit

Permalink
Fallback to trying to create bucket without LocationConstraint
Browse files Browse the repository at this point in the history
  • Loading branch information
hloeung committed Dec 4, 2024
1 parent c1c13ba commit b3ff9f4
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,28 @@ def _create_bucket_if_not_exists(self) -> None:
except ClientError:
logger.warning("Bucket %s doesn't exist or you don't have access to it.", bucket_name)
exists = False
if not exists:
try:
bucket.create(CreateBucketConfiguration={"LocationConstraint": region})
if exists:
return

bucket.wait_until_exists()
logger.info("Created bucket '%s' in region=%s", bucket_name, region)
except ClientError as error:
try:
bucket.create(CreateBucketConfiguration={"LocationConstraint": region})

bucket.wait_until_exists()
logger.info("Created bucket '%s' in region=%s", bucket_name, region)
except ClientError as error:
if error.response['Error']['Code'] == 'InvalidLocationConstraint':
logger.info("Specified location-constraint is not valid, trying create without it")
try:
bucket.create()

bucket.wait_until_exists()
logger.info("Created bucket '%s' in region=%s", bucket_name, region)
except ClientError as error:
logger.exception(
"Couldn't create bucket named '%s' in region=%s.", bucket_name, region
)
raise error
else:
logger.exception(
"Couldn't create bucket named '%s' in region=%s.", bucket_name, region
)
Expand Down

0 comments on commit b3ff9f4

Please sign in to comment.