Skip to content

Commit bc77951

Browse files
committed
fix(create_bucket): try default s3 region on create error
1 parent 6863e0b commit bc77951

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

rootfs/bin/create_bucket

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import boto.s3
66
import json
77
import swiftclient
88
from boto import config as botoconfig
9+
from boto.exception import S3CreateError
910
from boto.s3.connection import S3Connection, OrdinaryCallingFormat
1011
from oauth2client.service_account import ServiceAccountCredentials
1112
from gcloud.storage.client import Client
@@ -23,9 +24,20 @@ region = os.getenv('AWS_REGION')
2324

2425
if 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+
except S3CreateError as err:
31+
# try again in the default S3 region before giving up
32+
default_region = 'us-east-1'
33+
if region != default_region:
34+
print('Failed to create bucket in {}, trying default region {}...'.format(
35+
region, default_region))
36+
conn = boto.s3.connect_to_region(default_region)
37+
if not bucket_exists(conn, bucket_name):
38+
conn.create_bucket(bucket_name, location=default_region)
39+
# TODO: if we got here, somehow we need to propagate "us-east-1"
40+
# into WALE_S3_ENDPOINT...
2941

3042
elif os.getenv('DATABASE_STORAGE') == "gcs":
3143
scopes = ['https://www.googleapis.com/auth/devstorage.full_control']

0 commit comments

Comments
 (0)