From 8cf09969c19d86c25afc1eae6a2decb219eca00e Mon Sep 17 00:00:00 2001 From: "Daniel G. Taylor" Date: Wed, 19 Nov 2014 16:36:07 -0800 Subject: [PATCH 1/2] Update CloudTrail to use bucket location constraints This fixes the CloudTrail bucket creation code to work in regions other than `us-east-1` by setting a bucket configuration with a location constraint on the region. This is similar to how the S3 customizations work. --- awscli/customizations/cloudtrail.py | 10 +++++++++- tests/unit/customizations/test_cloudtrail.py | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) 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') From 7066800a517f4382ff4944314266f300d49120e6 Mon Sep 17 00:00:00 2001 From: "Daniel G. Taylor" Date: Thu, 20 Nov 2014 12:04:16 -0800 Subject: [PATCH 2/2] Update changelog [ci skip] --- CHANGELOG.rst | 3 +++ 1 file changed, 3 insertions(+) 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 `__)