帮助与文档

我们为你提供丰富、详尽的使用指南以及产品文档

使用示例

大多数基于 AWS S3 开发的工具都有自定义访问地址的方法,下面以一些常用工具为例,说明如何对接 QingStor

AWS SDK for Python

  1. 安装 Boto 类库:

    > pip install boto
    
  2. 编写程序:

    > cat boto-to-qingstor.py
    import boto
    conn = boto.connect_s3(
        aws_access_key_id='PLLZOBTTZXGBNOWUFHZZ',
        aws_secret_access_key='MnIjI58zC8AX07xotHXcm6grwFgOXhaJQHkTCX2X',
        host='s3.pek3a.qingstor.com'
    )
    bucket = conn.get_bucket('mybucket')
    key = bucket.get_key("mykey")
    

AWS CLI

  1. 安装 AWS CLI 工具:

    > pip install awscli
    
  2. 编辑配置文件:

    > cat ~/.aws/config
    [profile qingstor]
    region = pek3a
    output = json
    s3 =
        signature_version = s3v4
    
  3. 设置访问密钥:

    >  cat ~/.aws/credentials
    [qingstor]
    aws_access_key_id = PLLZOBTTZXGBNOWUFHZZ
    aws_secret_access_key = MnIjI58zC8AX07xotHXcm6grwFgOXhaJQHkTCX2X
    
  4. 命令行执行:

    > aws s3api put-object --bucket mybucket --key puppy.jpg --body ~/Pictures/puppy.jpg --endpoint-url 'https://s3.pek3a.qingstor.com' --profile qingstor
    {
        "ETag": "\"c3872b49cb244269aad8cd4275a41c4a\""
    }
    

s3fs

  1. 按照文档的步骤编译并安装 s3fs:

    https://github.com/s3fs-fuse/s3fs-fuse/blob/master/README.md
    
  2. 设置访问密钥(注意需要设置密钥文件的权限为 600):

    > cat  /root/.s3fs/credentials
    PLLZOBTTZXGBNOWUFHZZ:MnIjI58zC8AX07xotHXcm6grwFgOXhaJQHkTCX2X
    EOF
    
    > chmod 600 /root/.s3fs/credentials
    

    假定 ACCESS_KEY_ID 为 PLLZOBTTZXGBNOWUFHZZ, ACCESS_KEY_SECRET 为 MnIjI58zC8AX07xotHXcm6grwFgOXhaJQHkTCX2X

  3. 挂载 bucket 到本地目录:

    > mkdir -p /mnt/mybucket
    
    > s3fs mybucket /mnt/mybucket -o passwd_file=/root/.s3fs/credentials -o url=http://s3.pek3a.qingstor.com
    
    > df -T | grep s3fs
    s3fs           fuse.s3fs 274877906944        0 274877906944   0% /mnt/mybucket
    
  4. 测试文件系统操作:

    > echo 'hello world' > /tmp/hello.txt
    
    > cp -v /tmp/hello.txt /mnt/mybucket/
    ‘/tmp/hello.txt’ -> ‘/mnt/mybucket/hello.txt’
    
    > ls -l /mnt/mybucket/hello.txt
    ---------- 1 root root 4635 Aug 11 23:26 /mnt/mybucket/hello.txt
    
    > cat /mnt/mybucket/hello.txt
    hello world
    

s3cmd

  1. 安装 s3cmd 工具

    > pip install s3cmd
    
  2. 编辑配置文件

    > cat ~/.s3cfg
    [default]
    access_key = PLLZOBTTZXGBNOWUFHZZ
    secret_key = MnIjI58zC8AX07xotHXcm6grwFgOXhaJQHkTCX2X
    bucket_location = pek3a
    host_base = s3.pek3a.qingstor.com
    host_bucket = %(bucket)s.s3.pek3a.qingstor.com
    
  3. 命令行执行::

    > s3cmd put /tmp/hello.txt s3://mybucket/
    upload: '/tmp/hello.txt' -> 's3://mybucket/hello.txt'  [1 of 1]
    4635 of 4635   100% in    0s   523.36 B/s  done