@@ -6,6 +6,7 @@ import boto.s3
66import json
77import swiftclient
88from boto import config as botoconfig
9+ from boto .exception import S3CreateError
910from boto .s3 .connection import S3Connection , OrdinaryCallingFormat
1011from oauth2client .service_account import ServiceAccountCredentials
1112from gcloud .storage .client import Client
@@ -23,9 +24,20 @@ region = os.getenv('AWS_REGION')
2324
2425if os .getenv ('DATABASE_STORAGE' ) == "s3" :
2526 conn = boto .s3 .connect_to_region (region )
26-
2727 if not bucket_exists (conn , bucket_name ):
28- conn .create_bucket (bucket_name , location = region )
28+ try :
29+ conn .create_bucket (bucket_name , location = region )
30+ # NOTE(bacongobbler): for versions prior to v2.9.0, the bucket is created in the default region.
31+ # if we got here, we need to propagate "us-east-1" into WALE_S3_ENDPOINT because the bucket
32+ # exists in a different region and we cannot find it.
33+ # TODO(bacongobbler): deprecate this once we drop support for v2.8.0 and lower
34+ except S3CreateError as err :
35+ if region != 'us-east-1' :
36+ print ('Failed to create bucket in {}. We are now assuming that the bucket was created in us-east-1.' .format (region ))
37+ with open (os .path .join (os .environ ['WALE_ENVDIR' ], "WALE_S3_ENDPOINT" ), "w+" ) as file :
38+ file .write ('https+path://s3.amazonaws.com:443' )
39+ else :
40+ raise
2941
3042elif os .getenv ('DATABASE_STORAGE' ) == "gcs" :
3143 scopes = ['https://www.googleapis.com/auth/devstorage.full_control' ]
0 commit comments