Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update CloudTrail to use bucket location constraints #1013

Merged
merged 2 commits into from
Nov 20, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ CHANGELOG
Next Release (TBD)
==================

* bugfix:``aws cloudtrail create-subscription``: Set a bucket config
location constraint on buckets created outside of us-east-1.
(`issue 1013 <https://github.com/aws/aws-cli/pull/1013>`__)
* bugfix:``aws deploy push``: Fix s3 multipart uploads
* bugfix:``aws s3 ls``: Fix return codes for non existing objects
(`issue 1008 <https://github.com/aws/aws-cli/pull/1008>`__)
Expand Down
10 changes: 9 additions & 1 deletion awscli/customizations/cloudtrail.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,15 @@ def setup_new_bucket(self, bucket, prefix, policy_url=None):
raise Exception('Bucket {bucket} already exists.'.format(
bucket=bucket))

data = self.s3.CreateBucket(bucket=bucket)
# If we are not using the us-east-1 region, then we must set
# a location constraint on the new bucket.
region_name = self.s3.endpoint.region_name
params = {'bucket': bucket}
if region_name != 'us-east-1':
bucket_config = {'LocationConstraint': region_name}
params['create_bucket_configuration'] = bucket_config

data = self.s3.CreateBucket(**params)

try:
self.s3.PutBucketPolicy(bucket=bucket, policy=policy)
Expand Down
18 changes: 18 additions & 0 deletions tests/unit/customizations/test_cloudtrail.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,24 @@ def test_s3_create(self):

s3.DeleteBucket.assert_not_called()

args, kwargs = s3.CreateBucket.call_args
self.assertNotIn('create_bucket_configuration', kwargs)

def test_s3_create_non_us_east_1(self):
# Because this is outside of us-east-1, it should create
# a bucket configuration with a location constraint.
s3 = self.subscribe.s3
s3.endpoint.region_name = 'us-west-2'

self.subscribe.setup_new_bucket('test', 'logs')

args, kwargs = s3.CreateBucket.call_args
self.assertIn('create_bucket_configuration', kwargs)

bucket_config = kwargs['create_bucket_configuration']
self.assertEqual(bucket_config['LocationConstraint'],
'us-west-2')

def test_s3_create_already_exists(self):
with self.assertRaises(Exception):
self.subscribe.setup_new_bucket('test2', 'logs')
Expand Down