Creating a Bucket
API Description
You can use this API to create a bucket and name it as you specify. The created bucket name must be unique in OBS. If the same account creates buckets of the same name in the same region, no error will be reported and the bucket properties comply with those set in the first creation request. If the same account repeatedly creates buckets with the same name in the same region, status code 200 is returned. In other cases, status code 409 is returned, indicating that the bucket already exists. Each user can create a maximum of 100 buckets.
Method Definition
ObsClient.createBucket(bucketName, header, location)
Request Parameters
|
Field |
Type |
Optional or Mandatory |
Description |
|---|---|---|---|
|
bucketName |
str |
Mandatory |
Bucket name
A bucket name must comply with the following rules:
|
|
header |
Optional |
Additional header of the request for creating a bucket |
|
|
location |
str |
Mandatory unless the region where the OBS service resides is not the default region. |
Region where the bucket will be created. This parameter value must match the endpoint you use.
For details about OBS regions and endpoints, see Regions and Endpoints. |
Returned Results
|
Type |
Description |
|---|---|
|
SDK common result object |
Sample Code
With the endpoint of the default region CN North-Beijing1 (cn-north-1) used for bucket creation, you do not need to specify location and the bucket will be created in the CN North-Beijing1 region.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
try:
from obs import CreateBucketHeader
from obs import ObsClient
from obs import StorageClass
ak = '*** Provide your Access Key ***'
sk = '*** Provide your Secret Key ***'
server='https://obs.cn-north-1.myhuaweicloud.com'
obsClient = ObsClient(access_key_id=ak, secret_access_key=sk, server=server)
resp = obsClient.createBucket(bucketName='bucketname', header=CreateBucketHeader(aclControl='private', storageClass=StorageClass.WARM))
if resp.status < 300:
print('requestId:', resp.requestId)
else:
print('errorCode:', resp.errorCode)
print('errorMessage:', resp.errorMessage)
except:
import traceback
print(traceback.format_exc())
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
try:
from obs import CreateBucketHeader
from obs import ObsClient
ak = '*** Provide your Access Key ***'
sk = '*** Provide your Secret Key ***'
# Use the endpoint of a non-default region.
server = 'https://obs.other-region.myhuaweicloud.com'
obsClient = ObsClient(access_key_id=ak, secret_access_key=sk, server=server)
resp = obsClient.createBucket(bucketName='bucketname', location="other-region")
if resp.status < 300:
print('requestId:', resp.requestId)
else:
print('errorCode:', resp.errorCode)
print('errorMessage:', resp.errorMessage)
except:
import traceback
print(traceback.format_exc())
|
Last Article: Bucket-Related APIs
Next Article: Listing Buckets
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.