我想做的是从我的 EC2 机器连接 s3 存储桶。
如果我没有在
endpoint_url
中设置s3fs.S3FileSystem()
,就会出现此错误。
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/s3fs/core.py", line 246, in _call_s3
out = await method(**additional_kwargs)
File "/usr/local/lib/python3.7/site-packages/aiobotocore/client.py", line 155, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (AccessDenied) when calling the ListObjectsV2 operation: Access Denied
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/s3fs/core.py", line 1064, in _info
out = await self._simple_info(path)
File "/usr/local/lib/python3.7/site-packages/s3fs/core.py", line 984, in _simple_info
**self.req_kw,
File "/usr/local/lib/python3.7/site-packages/s3fs/core.py", line 265, in _call_s3
raise translate_boto_error(err)
PermissionError: Access Denied
但是,我可以通过在
endpoint_url
中添加 s3fs.S3FileSystem()
来指定区域来修复它。
s3 = s3fs.S3FileSystem(key=MYKEY,
secret=SECRET,
client_kwargs={
'endpoint_url':'https://s3.ap-northeast-2.amazonaws.com'
})
我想知道 s3fs 是否需要特定区域,因为文档中没有严格的指导..!
感谢您提前的帮助。
看来s3fs肯定需要特定的区域。如果您已在 aws 凭证中指定了配置文件并在 aws 配置中指定了区域,则可以使用如下配置文件:
from aiobotocore.session import AioSession
s3=s3fs.S3FileSystem(session=AioSession(profile='your_profile_name'))
这对我有用。 提示:“your_profile_name”表示 aws 凭证中的配置文件,如下所示:
[your_profile_name]
aws_access_key_id = AKIAxxxxxxx
aws_secret_access_key = xxxxxxxxx
我最终通过将
client_kwargs
传递给构造函数来解决这个问题:
import s3fs
s3 = s3fs.S3FileSystem(client_kwargs={'region_name': 'us-east-1'})
参考资料: