Skip to content

Commit

Permalink
Merge pull request #176 from bacongobbler/fixup-bucket-create
Browse files Browse the repository at this point in the history
fix(create_bucket): try default s3 region on create error
  • Loading branch information
Matthew Fisher authored Dec 5, 2016
2 parents 6863e0b + 8bf4c52 commit 1ef7a37
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions rootfs/bin/create_bucket
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import boto.s3
import json
import swiftclient
from boto import config as botoconfig
from boto.exception import S3CreateError
from boto.s3.connection import S3Connection, OrdinaryCallingFormat
from oauth2client.service_account import ServiceAccountCredentials
from gcloud.storage.client import Client
Expand All @@ -23,9 +24,20 @@ region = os.getenv('AWS_REGION')

if os.getenv('DATABASE_STORAGE') == "s3":
conn = boto.s3.connect_to_region(region)

if not bucket_exists(conn, bucket_name):
conn.create_bucket(bucket_name, location=region)
try:
conn.create_bucket(bucket_name, location=region)
# NOTE(bacongobbler): for versions prior to v2.9.0, the bucket is created in the default region.
# if we got here, we need to propagate "us-east-1" into WALE_S3_ENDPOINT because the bucket
# exists in a different region and we cannot find it.
# TODO(bacongobbler): deprecate this once we drop support for v2.8.0 and lower
except S3CreateError as err:
if region != 'us-east-1':
print('Failed to create bucket in {}. We are now assuming that the bucket was created in us-east-1.'.format(region))
with open(os.path.join(os.environ['WALE_ENVDIR'], "WALE_S3_ENDPOINT"), "w+") as file:
file.write('https+path://s3.amazonaws.com:443')
else:
raise

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

0 comments on commit 1ef7a37

Please sign in to comment.