瀏覽代碼

HUE-6658 [aws] Use region as a the default if both region and endpoint are undefined

Jenny Kim 8 年之前
父節點
當前提交
c95a76041b

+ 1 - 1
desktop/conf.dist/hue.ini

@@ -1378,7 +1378,7 @@
       ## allow_environment_credentials=yes
 
       # AWS region to use, if no region is specified, will attempt to connect to standard s3.amazonaws.com endpoint
-      ## region=
+      ## region=us-east-1
 
       # Endpoint overrides
       ## host=

+ 1 - 1
desktop/conf/pseudo-distributed.ini.tmpl

@@ -1380,7 +1380,7 @@
       ## allow_environment_credentials=yes
 
       # AWS region to use, if no region is specified, will attempt to connect to standard s3.amazonaws.com endpoint
-      ## region=
+      ## region=us-east-1
 
       # Endpoint overrides
       ## host=

+ 6 - 3
desktop/libs/aws/src/aws/client.py

@@ -81,8 +81,6 @@ class Client(object):
     )
 
   def get_s3_connection(self):
-    # Use V4 signature support by default
-    os.environ['S3_USE_SIGV4'] = 'True'
 
     kwargs = {
       'aws_access_key_id': self._access_key_id,
@@ -105,10 +103,15 @@ class Client(object):
     # Attempt to create S3 connection based on configured credentials and host or region first, then fallback to IAM
     try:
       if self._host is not None:
+        # Use V4 signature support by default
+        os.environ['S3_USE_SIGV4'] = 'True'
         kwargs.update({'host': self._host})
         connection = boto.s3.connection.S3Connection(**kwargs)
       elif self._region:
-        connection = boto.s3.connect_to_region(self._region, **kwargs)
+        connection = boto.s3.connect_to_region(self._region,
+                                             aws_access_key_id=self._access_key_id,
+                                             aws_secret_access_key=self._secret_access_key,
+                                             security_token=self._security_token)
       else:
         kwargs.update({'host': 's3.amazonaws.com'})
         connection = boto.s3.connection.S3Connection(**kwargs)

+ 1 - 1
desktop/libs/aws/src/aws/conf.py

@@ -97,7 +97,7 @@ AWS_ACCOUNTS = UnspecifiedConfigSection(
       ),
       REGION=Config(
         key='region',
-        default=None,
+        default='us-east-1',
         type=str
       ),
       HOST=Config(

+ 3 - 6
desktop/libs/aws/src/aws/s3/s3fs.py

@@ -142,16 +142,13 @@ class S3FileSystem(object):
     except S3ResponseError, e:
       if e.status == 301:
         raise S3FileSystemException(_('Failed to access path: "%s" '
-          'Check that you have access to read this bucket and that the region is correct.') % path)
+          'Check that you have access to read this bucket and that the region is correct: %s') % (path, e.message or e.reason))
       else:
         raise S3FileSystemException(e.message or e.reason)
 
   def _get_location(self):
-
-    if get_default_region() in (Location.EU, Location.EUCentral1, Location.EUWest, Location.EUWest2,
-                                Location.CACentral, Location.USEast, Location.USEast2, Location.USWest,
-                                Location.USWest2, Location.SAEast, Location.APNortheast, Location.APNortheast2,
-                                Location.APSoutheast, Location.APSoutheast2, Location.APSouth, Location.CNNorth1):
+    if get_default_region() in (Location.EU, Location.EUCentral1, Location.CACentral, Location.USWest, Location.USWest2, Location.SAEast,
+                                Location.APNortheast, Location.APSoutheast, Location.APSoutheast2, Location.CNNorth1):
       return get_default_region()
     else:
       return Location.DEFAULT