diff --git a/CHANGELOG.rst b/CHANGELOG.rst index c07d0f7a21b7..650c9b9aac7c 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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 `__) * bugfix:``aws deploy push``: Fix s3 multipart uploads * bugfix:``aws s3 ls``: Fix return codes for non existing objects (`issue 1008 `__) diff --git a/awscli/customizations/cloudtrail.py b/awscli/customizations/cloudtrail.py index ae55cc2cab67..f99489301e2f 100644 --- a/awscli/customizations/cloudtrail.py +++ b/awscli/customizations/cloudtrail.py @@ -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) diff --git a/tests/unit/customizations/test_cloudtrail.py b/tests/unit/customizations/test_cloudtrail.py index c705afb4195b..d4c24c26b8f1 100644 --- a/tests/unit/customizations/test_cloudtrail.py +++ b/tests/unit/customizations/test_cloudtrail.py @@ -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')