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 )