@@ -76,15 +76,18 @@ class meta:
7676 PATH_MAX = None
7777 NAME_MAX = None
7878
79- def __init__ (self , bucket , prefix = "" , aws_access_key = None , aws_secret_key = None , separator = "/" , thread_synchronize = True , key_sync_timeout = 1 ):
79+ def __init__ (self , bucket , prefix = "" , aws_access_key = None , aws_secret_key = None , separator = "/" , thread_synchronize = True , key_sync_timeout = 1 , ** conn_kwargs ):
8080 """Constructor for S3FS objects.
8181
8282 S3FS objects require the name of the S3 bucket in which to store
8383 files, and can optionally be given a prefix under which the files
84- should be stored. The AWS public and private keys may be specified
85- as additional arguments; if they are not specified they will be
86- read from the two environment variables AWS_ACCESS_KEY_ID and
87- AWS_SECRET_ACCESS_KEY.
84+ should be stored. AWS connection arguments (e.g. aws_access_key_id,
85+ aws_secret_access_key, etc) may be specified as additional keyword
86+ arguments to be passed to boto.s3.connection.S3Connection; if they
87+ are not specified boto will try to read them from various locations (
88+ see http://boto.cloudhackers.com/en/latest/boto_config_tut.html). Note
89+ that legacy arguments 'aws_access_key' and 'aws_secret_key' will be
90+ passed to boto as 'aws_access_key_id' and 'aws_secret_access_key'.
8891
8992 The keyword argument 'key_sync_timeout' specifies the maximum
9093 time in seconds that the filesystem will spend trying to confirm
@@ -97,7 +100,11 @@ def __init__(self, bucket, prefix="", aws_access_key=None, aws_secret_key=None,
97100 by specifying the keyword 'separator' in the constructor.
98101 """
99102 self ._bucket_name = bucket
100- self ._access_keys = (aws_access_key ,aws_secret_key )
103+ if aws_access_key is not None :
104+ conn_kwargs ['aws_access_key_id' ] = aws_access_key
105+ if aws_secret_key is not None :
106+ conn_kwargs ['aws_secret_access_key' ] = aws_secret_key
107+ self ._conn_kwargs = conn_kwargs
101108 self ._separator = separator
102109 self ._key_sync_timeout = key_sync_timeout
103110 # Normalise prefix to this form: path/to/files/
@@ -108,12 +115,6 @@ def __init__(self, bucket, prefix="", aws_access_key=None, aws_secret_key=None,
108115 prefix = prefix + separator
109116 if isinstance (prefix ,unicode ):
110117 prefix = prefix .encode ("utf8" )
111- if aws_access_key is None :
112- if "AWS_ACCESS_KEY_ID" not in os .environ :
113- raise CreateFailedError ("AWS_ACCESS_KEY_ID not set" )
114- if aws_secret_key is None :
115- if "AWS_SECRET_ACCESS_KEY" not in os .environ :
116- raise CreateFailedError ("AWS_SECRET_ACCESS_KEY not set" )
117118 self ._prefix = prefix
118119 self ._tlocal = thread_local ()
119120 super (S3FS , self ).__init__ (thread_synchronize = thread_synchronize )
@@ -128,7 +129,7 @@ def _s3conn(self):
128129 raise AttributeError
129130 return c
130131 except AttributeError :
131- c = boto .s3 .connection .S3Connection (* self ._access_keys )
132+ c = boto .s3 .connection .S3Connection (** self ._conn_kwargs )
132133 self ._tlocal .s3conn = (c ,time .time ())
133134 return c
134135 _s3conn = property (_s3conn )
0 commit comments