兼容工具示例
Last updated
2023-07-12 15:21:57
{"value":"\u5bf9\u5927\u591a\u6570\u57fa\u4e8eAWS S3\u5f00\u53d1\u7684\u5de5\u5177\uff0c\u8fdb\u884c\u5982\u4e0b\u6539\u52a8\u5373\u53ef\u8bbf\u95ee\u79c1\u6709\u4e91\u5bf9\u8c61\u5b58\u50a8\uff1a\n\n1. \u83b7\u53d6CDNCLOUD\u8d26\u53f7\u7684AccessKey\u548cSecretKey\uff0c\u5728\u60a8\u4f7f\u7528\u7684\u5ba2\u6237\u7aef\u548cSDK\u4e2d\u914d\u7f6eCDNCLOUD\u7684AccessKey\u548cSecretKey\u3002\n2. \u8bbe\u7f6e\u5ba2\u6237\u7aef\u8fde\u63a5\u7684Endpoint\u4e3a\u79c1\u6709\u4e91\u5bf9\u8c61\u5b58\u50a8 S3 \u7684 Endpoint\u3002\n\n\u53ea\u8981\u6d89\u53ca\u7684\u63a5\u53e3\u5b9e\u73b0\u4e86\u517c\u5bb9\uff0c\u5373\u53ef\u5728\u5de5\u5177\u4e2d\u4f7f\u7528\u5bf9\u5e94\u7684\u529f\u80fd\uff0c\u5bf9\u63a5\u79c1\u6709\u4e91\u5bf9\u8c61\u5b58\u50a8\u3002\n\n\u4e0b\u9762\u4ee5\u4e00\u4e9b\u5de5\u5177\u4e3a\u4f8b\uff0c\u5177\u4f53\u8bf4\u660e\u5bf9\u63a5\u65b9\u5f0f\u3002\n\n# **AWS SDK for Golang**\n\n1 \u5b89\u88c5\uff0c\u53ef\u53c2\u8003[\u5b98\u65b9\u6587\u6863](https:\/\/aws.amazon.com\/cn\/sdk-for-go\/)\n\n```\ngo get github.com\/aws\/aws-sdk-go\n```\n\n2 \u4f7f\u7528AWS SDK for Golang \u8bbf\u95ee\u79c1\u6709\u4e91\u5b58\u50a8\n\n```\npackage main\n\nimport (\n \"github.com\/aws\/aws-sdk-go\/aws\"\n \"github.com\/aws\/aws-sdk-go\/aws\/credentials\"\n \"github.com\/aws\/aws-sdk-go\/aws\/session\"\n \"github.com\/aws\/aws-sdk-go\/service\/s3\"\n)\n\nconst (\n s3endpoint = \"<qiniu-s3-endpoint>\"\n s3region = \"cn-east-1\"\n s3accessKeyId = \"<your-qiniu-access-key-id>\"\n s3SecretKeyId = \"<your-qiniu-secret-key-id>\"\n)\n\nfunc main() {\n conf := &aws.Config{\n Region: aws.String(s3region),\n Endpoint: aws.String(s3endpoint),\n Credentials: credentials.NewStaticCredentials(s3accessKeyId, s3SecretKeyId, \"\"),\n }\n\n sess := session.Must(session.NewSessionWithOptions(session.Options{Config:*conf}))\n\n svc := s3.New(sess)\n\n input := &s3.ListBucketsInput{}\n\n result, err := svc.ListBuckets(input)\n if err != nil {\n panic(err.Error())\n }\n\n println(result.String())\n}\n```\n\n\n\n# **AWS SDK for Python**\n\n1 \u901a\u8fc7pip\u5b89\u88c5boto3\uff0c\u5b89\u88c5\u8bf4\u660e\u53ef\u53c2\u8003[\u5b98\u65b9\u6587\u6863](https:\/\/boto3.amazonaws.com\/v1\/documentation\/api\/latest\/index.html)\n\n```\npip install boto3\n```\n\n2 \u4f7f\u7528AWS SDK for Python\u8bbf\u95ee\u79c1\u6709\u4e91\u5bf9\u8c61\u5b58\u50a8\n\n```\nimport boto3\nfrom botocore.client import Config\n\n\n# Config\ns3endpoint = '<qiniu-s3-endpoint>'\ns3region = 'cn-east-1'\ns3accessKeyId = '<your-qiniu-access-key-id>'\ns3SecretKeyId = '<your-qiniu-secret-key-id>'\n\n\n# Use S3 client\ns3client = boto3.client(\n 's3',\n aws_access_key_id = s3accessKeyId,\n aws_secret_access_key = s3SecretKeyId,\n endpoint_url = s3endpoint,\n region_name = s3region\n )\n\n\n# List buckets\nbuckets = s3client.list_buckets()\n\n# Output the bucket names\nfor bucket in buckets['Buckets']:\n print(bucket[\"Name\"])\n\n\n# Use S3 resource\ns3resource = boto3.resource('s3',\n endpoint_url = s3endpoint,\n region_name = s3region,\n aws_access_key_id = s3accessKeyId,\n aws_secret_access_key = s3SecretKeyId\n )\n\n\n# List buckets\nbuckets = s3resource.buckets.all()\n\n# Output the bucket names\nfor bucket in buckets:\n print(bucket.name)\n```\n\n\n\n\n\n# **AWS SDK for Java**\n\n1 \u8bbe\u7f6e\u5de5\u5177\u5305\uff0c\u53ef\u53c2\u8003[\u5b98\u65b9\u6587\u6863](https:\/\/docs.aws.amazon.com\/zh_cn\/sdk-for-java\/v2\/developer-guide\/setup-install.html)\uff08\u5efa\u8bae\u60a8\u4f7f\u7528\u6700\u65b0\u7248\u672c\u7684 java sdk\uff09 2 \u4f7f\u7528 AWS SDK for Java \u8bbf\u95ee\u79c1\u6709\u4e91\u5bf9\u8c61\u5b58\u50a8\n\n```\nimport java.io.IOException;\nimport com.amazonaws.auth.BasicAWSCredentials;\nimport com.amazonaws.services.s3.AmazonS3;\nimport com.amazonaws.services.s3.AmazonS3Client;\nimport com.amazonaws.services.s3.S3ClientOptions;\nimport com.amazonaws.services.s3.model.Bucket;\n\npublic class S3 {\n public static void main(String[] args) throws IOException {\n String s3endpoint = \"<qiniu-s3-endpoint>\";\n String accessKeyId = \"<your-qiniu-access-key-id>\";\n String accessKeySecret = \"<your-qiniu-secret-key-id>\";\n\n AmazonS3 s3 = new AmazonS3Client(new BasicAWSCredentials(accessKeyId,accessKeySecret));\n s3.setEndpoint(s3endpoint);\n\n S3ClientOptions options = new S3ClientOptions();\n options.withChunkedEncodingDisabled(true);\n s3.setS3ClientOptions(options);\n\n for (Bucket bucket : s3.listBuckets()) {\n System.out.println(\" - \" + bucket.getName());\n }\n\n }\n\n}\n```\n\n# **CloudBerry Explorer for Amazon S3**\n\nCloudBerry Explorer for Amazon S3\u662fCloudBerry Lab\u63d0\u4f9b\u7684S3\u56fe\u5f62\u5316\u6570\u636e\u7ba1\u7406\u8f6f\u4ef6\uff0c\u652f\u6301\u6570\u636e\u4ece\u672c\u5730\u5230\u4e91\u7aef\u7684\u4e0a\u4f20\u3001\u4e0b\u8f7d\u3001\u540c\u6b65\u3001\u5220\u9664\u7b49\u7ba1\u7406\u64cd\u4f5c\u3002\u901a\u8fc7\u4e00\u4e0b\u914d\u7f6e\u65b9\u5f0f\uff0c\u60a8\u4e5f\u53ef\u4ee5\u4f7f\u7528CloudBerry Explorer for Amazon S3\u7ba1\u7406\u60a8\u5728\u79c1\u6709\u4e91\u5b58\u50a8\u7684\u8d44\u6e90\u3002\n\n1 \u4e0b\u8f7d\u5b89\u88c5[CloudBerry Explorer for Amazon S3](https:\/\/www.cloudberrylab.com\/explorer\/amazon-s3.aspx)\n\n2 \u5b89\u88c5\u5b8c\u6210\u540e\u6253\u5f00\uff0c\u9009\u62e9\u300eS3 Compatible\u300f\u8fdb\u884c\u4e91\u5b58\u50a8\u914d\u7f6e\n\n![](https:\/\/tp2lravq.hk03.1112oss.com\/20230712151842nm0p278ake6c6h0mtd3ptl8pnviecdwf.png)\n\n3 \u6dfb\u52a0\u65b0\u7684S3 Compatible\u7684\u8d26\u53f7\uff0cDisplay name\u53ef\u4ee5\u586b\u5199Qiniu\uff0cService point \u5373\u79c1\u6709\u4e91S3\u7684\u670d\u52a1\u57df\u540d\uff0cAccess Key\u548cSecret Key\u586b\u5199\u5bf9\u8c61\u5b58\u50a8\u7684AK\/SK\uff0cSignature version\u90094\u3002\u70b9\u51fb\"Test Connection\"\uff0c\u663e\u793a\u201cConnection Success\u201d\u8868\u793a\u8fde\u63a5\u6210\u529f\u3002\n\n![](https:\/\/tp2lravq.hk03.1112oss.com\/20230712151624rerthf9kunbcg1djfhlsvb5j832k4ssr.png)\n\n4 \u73b0\u5728\u5c31\u53ef\u4ee5\u901a\u8fc7CloudBerry Explorer for Amazon S3\u5b9e\u73b0bucket\u548c\u6587\u4ef6\u7684\u7ba1\u7406\u3002\n\n\u6ce8\uff1aCloudBerry Explorer for Amazon S3 \u5bf9 S3 Compatible \u548c Amazon S3 \u4e24\u79cd\u914d\u7f6e\u7684\u4e91\u5b58\u50a8\u652f\u6301\u7684\u529f\u80fd\u672c\u8eab\u5c31\u6709\u533a\u522b\uff0c\u5982\u751f\u547d\u5468\u671f\u3001\u52a0\u5bc6\u7b49\u5747\u4e0d\u652f\u6301\u3002\n\n# **S3 Browser**\n\nS3 Browser\u662f\u4e00\u79cd\u6613\u4e8e\u4f7f\u7528\u548c\u5f3a\u5927\u7684Amazon S3\u514d\u8d39\u5ba2\u6237\u7aef\uff0c\u901a\u8fc7\u56fe\u5f62\u5316\u754c\u9762\u7ba1\u7406Amazon S3\u3002\u79c1\u6709\u4e91\u5b58\u50a8\u540c\u6837\u652f\u6301\u901a\u8fc7\u914d\u7f6e\u540e\u4f7f\u7528S3 Browser\u8fdb\u884c\u6587\u4ef6\u4e0a\u4f20\u3001\u4e0b\u8f7d\u3001bucket\u7ba1\u7406\u7b49\u64cd\u4f5c\u3002\n\n1 \u4e0b\u8f7d\u5b89\u88c5[S3 Browser](https:\/\/s3browser.com\/download.aspx)\n\n2 \u5b89\u88c5\u5b8c\u6210\u540e\u6253\u5f00\uff0c\u6dfb\u52a0\u79c1\u6709\u4e91\u5b58\u50a8\u8d26\u53f7\u3002Account Type\u9009\u62e9 \u201cS3 Compatible Storage\"\uff0cREST Endpoint\u586b\u5199\u79c1\u6709\u4e91\u5b58\u50a8S3\u7684\u670d\u52a1\u57df\u540d\uff0cSignature Version\u9009\u62e9Signature V4\uff0cAccess Key ID\u548cSecret Access Key\u586b\u5199\u79c1\u6709\u4e91\u5b58\u50a8\u7684AK\/SK\u3002\n![](https:\/\/tp2lravq.hk03.1112oss.com\/2023071215165308rwamjjui7bl6l9wrfgjnmf8hivtj1d.png)\n\n\n3 \u6dfb\u52a0\u6210\u529f\u540e\u53ef\u4ee5\u770b\u5230bucket\u5217\u8868\uff0c\u73b0\u5728\u5c31\u53ef\u4ee5\u901a\u8fc7S3 Browser\u8fdb\u884cbucket\u548c\u6587\u4ef6\u7ba1\u7406\uff0c\u5177\u4f53\u652f\u6301\u7684\u529f\u80fd\u53ef\u53c2\u8003\u517c\u5bb9\u63a5\u53e3\u3002 \n![](https:\/\/tp2lravq.hk03.1112oss.com\/202307121517094osmhd640ec4gq2tg7m9bm0c0oo7tbjj.png)\n\n\nS3fs\u662f\u57fa\u4e8eFUSE\u7684\u6587\u4ef6\u7cfb\u7edf\uff0c\u5141\u8bb8Linux\u548cMac Os X \u6302\u8f7dS3\u7684\u5b58\u50a8\u6876\u5728\u672c\u5730\u6587\u4ef6\u7cfb\u7edf\uff0cS3fs\u80fd\u591f\u4fdd\u6301\u5bf9\u8c61\u539f\u6765\u7684\u683c\u5f0f\u3002\u73b0\u5728\u60a8\u4e5f\u53ef\u4ee5\u901a\u8fc7S3fs\u5de5\u5177\u6302\u8f7d\u79c1\u6709\u4e91\u5b58\u50a8\u3002\n\n1 \u6309\u7167\u5b98\u65b9\u6587\u6863\u5b89\u88c5 [s3fs](https:\/\/github.com\/s3fs-fuse\/s3fs-fuse)\n\n2 \u5c06\u79c1\u6709\u4e91\u5b58\u50a8\u7684AK\/SK \u5199\u5165\u5bc6\u94a5\u6587\u4ef6\uff0c\u6bd4\u5982 \/root\/.passwd-s3fs\uff0c\u5e76\u5c06\u5bc6\u94a5\u6587\u4ef6\u6743\u9650\u8bbe\u4e3a600\n\n```\necho AK:SK > \/root\/.passwd-s3fs\nchmod 600 \/root\/.passwd-s3fs\n```\n\n3 \u5c06\u5df2\u7ecf\u5b58\u5728\u7684bucket\u6302\u8f7d\u5230\u672c\u5730\u76ee\u5f55\uff0curl\u586b\u5199\u79c1\u6709\u4e91\u5b58\u50a8s3\u7684\u670d\u52a1\u57df\u540d\uff0c\u5982 \/mnt\/s3fs\n\n```\ns3fs bucketname \/mnt\/s3fs -o passwd_file=\/root\/.passwd-s3fs -o url=endpoint -o use_path_request_style\n```\n\n4 \u9a8c\u8bc1\u6587\u4ef6\u64cd\u4f5c\n```\necho 'Hello,world!' > test.txt\ncp -v test.txt \/mnt\/s3fs\n```"}