1.获取Access Key和Secret Key
创建了obs资源后,进入 我的凭证->访问密钥->新增访问密钥
Ps:只能创建两次密钥,一定要保存好!!!
2.Python接口访问
连接S3
主机名和auth_region_name根据自己所在区域而定,我这里是cn-north-4
import boto
import boto.s3.connection
access_key = 'put your access key here!'
secret_key = 'put your secret key here!'
conn = boto.connect_s3(
aws_access_key_id = access_key,
aws_secret_access_key = secret_key,
host = ' obs.cn-north-4.myhuaweicloud.com',
#is_secure=False, # uncomment if you are not using ssl
calling_format = boto.s3.connection.OrdinaryCallingFormat(),
)
conn.auth_region_name = 'cn-north-4'
创建桶
conn.create_bucket(bucket_name,headers=None,location='cn-north-4', policy=None)
删除桶
必须为空桶才能删除
conn.delete_bucket(bucket.name)
列举所有桶的对象
for bucket in conn.get_all_buckets():
print ("{name}\t{created}".format(
name = bucket.name,
created = bucket.creation_date,
))
列举某个桶的对象
for key in bucket.list():
print "{name}\t{size}\t{modified}".format(
name = key.name,
size = key.size,
modified = key.last_modified,
)
上传对象