From b3ff9f422c72d018e9d77b8fe0c06e395d4f61d8 Mon Sep 17 00:00:00 2001 From: Haw Loeung Date: Wed, 4 Dec 2024 19:25:44 +1100 Subject: [PATCH] Fallback to trying to create bucket without LocationConstraint --- src/backups.py | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/backups.py b/src/backups.py index f661458467..d22703db50 100644 --- a/src/backups.py +++ b/src/backups.py @@ -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 )