Created
October 5, 2019 09:13
-
-
Save Leechael/1b81bfcc235823d4e928bf96e666d7b6 to your computer and use it in GitHub Desktop.
fs-s3fs for Aliyun OSS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from fs_s3fs import S3FS | |
import boto3 | |
from botocore.client import Config | |
class OSSFS(S3FS): | |
@property | |
def s3(self): | |
if not hasattr(self._tlocal, "s3"): | |
self._tlocal.s3 = boto3.resource( | |
"s3", | |
region_name=self.region, | |
aws_access_key_id=self.aws_access_key_id, | |
aws_secret_access_key=self.aws_secret_access_key, | |
aws_session_token=self.aws_session_token, | |
endpoint_url=self.endpoint_url, | |
config=Config(s3={'addressing_style': 'virtual'}) | |
) | |
return self._tlocal.s3 | |
@property | |
def client(self): | |
if not hasattr(self._tlocal, "client"): | |
self._tlocal.client = boto3.client( | |
"s3", | |
region_name=self.region, | |
aws_access_key_id=self.aws_access_key_id, | |
aws_secret_access_key=self.aws_secret_access_key, | |
aws_session_token=self.aws_session_token, | |
endpoint_url=self.endpoint_url, | |
config=Config(s3={'addressing_style': 'virtual'}) | |
) | |
return self._tlocal.client |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment