From 5188f77e368c173fdf721d088c72157a52c047e7 Mon Sep 17 00:00:00 2001 From: Andy Boyett Date: Wed, 22 Feb 2017 01:43:03 -0800 Subject: [PATCH] fix(create_bucket): avoid S3 InvalidLocationConstraint error calling create_bucket(bucket_name, region="us-east-1") yields the following error: boto.exception.S3ResponseError: S3ResponseError: 400 Bad Request InvalidLocationConstraint The specified location-constraint is not valid us-east-1... based on the comments in boto/boto3#125 this commit omits the region kwarg to the create_bucket() call when `s3.region` is set to "us-east-1" --- rootfs/bin/create_bucket | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rootfs/bin/create_bucket b/rootfs/bin/create_bucket index 8df8fca..2d23f63 100755 --- a/rootfs/bin/create_bucket +++ b/rootfs/bin/create_bucket @@ -26,7 +26,11 @@ if os.getenv('DATABASE_STORAGE') == "s3": conn = boto.s3.connect_to_region(region) if not bucket_exists(conn, bucket_name): try: - conn.create_bucket(bucket_name, location=region) + if region == "us-east-1": + # use "US Standard" region. workaround for https://github.com/boto/boto3/issues/125 + conn.create_bucket(bucket_name) + else: + 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.