Bläddra i källkod

HUE-7082 [aws] Create S3 bucket fails with error Bad request

jdesjean 8 år sedan
förälder
incheckning
ef13ceb
1 ändrade filer med 12 tillägg och 1 borttagningar
  1. 12 1
      desktop/libs/aws/src/aws/s3/s3fs.py

+ 12 - 1
desktop/libs/aws/src/aws/s3/s3fs.py

@@ -110,7 +110,7 @@ class S3FileSystem(object):
         kwargs = {}
         kwargs = {}
         if self._get_location():
         if self._get_location():
           kwargs['location'] = self._get_location()
           kwargs['location'] = self._get_location()
-        bucket = self._s3_connection.create_bucket(name, **kwargs)
+        bucket = self._create_bucket(name, **kwargs)
         self._bucket_cache[name] = bucket
         self._bucket_cache[name] = bucket
       elif e.status == 400:
       elif e.status == 400:
         raise S3FileSystemException(_('Failed to create bucket named "%s": %s') % (name, e.reason))
         raise S3FileSystemException(_('Failed to create bucket named "%s": %s') % (name, e.reason))
@@ -118,6 +118,17 @@ class S3FileSystem(object):
         raise S3FileSystemException(e.message or e.reason)
         raise S3FileSystemException(e.message or e.reason)
     return bucket
     return bucket
 
 
+  def _create_bucket(self, name, **kwargs):
+    # S3 API throws an exception when using us-east-1 and specifying CreateBucketConfiguration
+    # Boto specifies CreateBucketConfiguration whenever the location is not default
+    # We change location to default to fix issue
+    # More information: https://github.com/boto/boto3/issues/125
+
+    if 'location' in kwargs and kwargs['location'] == Location.USEast:
+      kwargs['location'] = Location.DEFAULT
+
+    return self._s3_connection.create_bucket(name, **kwargs)
+
   def _delete_bucket(self, name):
   def _delete_bucket(self, name):
     try:
     try:
       # Verify that bucket exists and user has permissions to access it
       # Verify that bucket exists and user has permissions to access it