Skip to content

Commit

Permalink
Merge pull request #23 from remind101/gh-17
Browse files Browse the repository at this point in the history
Create bucket in correct region
  • Loading branch information
phobologic committed Apr 2, 2015
2 parents 402b0df + d41a74d commit 109830b
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion stacker/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,21 @@ def conn(self):
self._conn = ConnectionManager(self.region)
return self._conn

def get_bucket_location(self):
""" Determines what region the S3 bucket should be created in.
This is annoying - rather than creating the bucket in the region that
you are connected to, create_bucket needs a special extra argument.
Even worse, it uses the region for everywhere BUT us-east-1, which
is instead blank.
"""
if self.region == 'us-east-1':
location = ''
else:
location = self.region
return location

@property
def cfn_bucket(self):
if not getattr(self, '_cfn_bucket', None):
Expand All @@ -71,7 +86,9 @@ def cfn_bucket(self):
except S3ResponseError, e:
if e.error_code == 'NoSuchBucket':
logger.debug("Creating bucket %s.", self.cfn_domain)
self._cfn_bucket = s3.create_bucket(self.cfn_domain)
self._cfn_bucket = s3.create_bucket(
self.cfn_domain,
location=self.get_bucket_location())
else:
logger.exception("Error creating bucket %s.",
self.cfn_domain)
Expand Down

0 comments on commit 109830b

Please sign in to comment.