@@ -6,6 +6,7 @@ import boto.s3
6
6
import json
7
7
import swiftclient
8
8
from boto import config as botoconfig
9
+ from boto .exception import S3CreateError
9
10
from boto .s3 .connection import S3Connection , OrdinaryCallingFormat
10
11
from oauth2client .service_account import ServiceAccountCredentials
11
12
from gcloud .storage .client import Client
@@ -23,9 +24,20 @@ region = os.getenv('AWS_REGION')
23
24
24
25
if os .getenv ('DATABASE_STORAGE' ) == "s3" :
25
26
conn = boto .s3 .connect_to_region (region )
26
-
27
27
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
29
41
30
42
elif os .getenv ('DATABASE_STORAGE' ) == "gcs" :
31
43
scopes = ['https://www.googleapis.com/auth/devstorage.full_control' ]
0 commit comments