• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. API Reference (Python SDK)
  4. Bucket-Related APIs
  5. PUT Bucket

PUT 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 a user repeatedly creates buckets with the same name in one region, status code 200 is returned. In other cases, status code 409 is returned. Each user can create a maximum of 100 buckets.

Method Definition

ObsClient.createBucket(bucketName, header, location)

Request Parameter

Field

Type

Optional or Mandatory

Description

bucketName

str

Mandatory

Bucket name

A bucket name must comply with the following rules:
  • Contains 3 to 63 characters chosen from lowercase letters, digits, hyphens (-), and periods (.), and starts with a digit or letter.
  • Cannot be an IP-like address.
  • Cannot start or end with a hyphen (-) or period (.).
  • Cannot contain two consecutive periods (.), for example, my..bucket.
  • Cannot contain periods (.) and hyphens (-) adjacent to each other, for example, my-.bucket or my.-bucket.

header

CreateBucketHeader

Optional

Additional header in PUT Bucket

location

str

Mandatory unless the region where the OBS service resides is not the default region.

Bucket location

For details about OBS regions and endpoints, see Regions and Endpoints.

Returned Result

Type

Description

GetResult

SDK common result object

Sample Code

try:
    from com.obs.models.create_bucket_header import CreateBucketHeader 
    resp = obsClient.createBucket(bucketName='bucketname', header=CreateBucketHeader(aclControl='private', storageClass='STANDARD_IA')) 
     
    if resp.status < 300: 
        print('requestId:', resp.requestId) 
    else: 
        print('errorCode:', resp.errorCode) 
        print('errorMessage:', resp.errorMessage)
except:
    import traceback
    print(traceback.format_exc())