Skip to content

Commit fdb6432

Browse files
authored
InvalidLocationConstraint error in AWS S3 handled. (#1403)
1 parent b95477a commit fdb6432

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lithops/storage/backends/aws_s3/aws_s3.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,14 @@ def create_bucket(self, bucket_name):
8787
logger.debug(f"Could not find the bucket {bucket_name} in the AWS S3 storage backend")
8888
logger.debug(f"Creating new bucket {bucket_name} in the AWS S3 storage backend")
8989
bucket_config = {'LocationConstraint': self.region}
90-
self.s3_client.create_bucket(Bucket=bucket_name, CreateBucketConfiguration=bucket_config)
90+
try:
91+
self.s3_client.create_bucket(Bucket=bucket_name, CreateBucketConfiguration=bucket_config)
92+
except botocore.exceptions.ClientError as ce:
93+
error_code = ce.response.get('Error', {}).get('Code', 'Unknown')
94+
if error_code == "InvalidLocationConstraint" and self.region == "us-east-1":
95+
self.s3_client.create_bucket(Bucket=bucket_name)
96+
else:
97+
raise ce
9198
else:
9299
raise e
93100

0 commit comments

Comments
 (0)