Configuring a Bucket Policy

API Description

You can use this API to configure bucket policies. With the policies configured, bucket owners can have centralized access control over buckets and their objects. For details about the format, see Policy Format, for bucket policies, see Introduction to OBS Permission Control, and for bucket policy examples, see Bucket Policy.

The last policy configuration will overwrite the original one when you call the API for configuring a bucket policy. For example, if you have configured bucket policies A, B, C, and D and you want to add a new bucket policy E, add policy E to the file containing the existing four policies and then upload the file with all policies contained.

Likewise, if you want to delete bucket policy D, remove it from the file containing policies A, B, C, and D, and then upload the file without policy D contained.

Method Definition

ObsClient.setBucketPolicy(bucketName, policyJSON)

Request Parameters

Field

Type

Optional or Mandatory

Description

bucketName

str

Mandatory

Bucket name

policyJSON

str

Mandatory

Policy information in JSON format.

Returned Results

Type

Description

GetResult

SDK common result object

Sample Code

try:
    resp = obsClient.setBucketPolicy('bucketname', 'your policy') 
     
    if resp.status < 300: 
        print('requestId:', resp.requestId) 
    else: 
        print('errorCode:', resp.errorCode) 
        print('errorMessage:', resp.errorMessage)
except:
    import traceback
    print(traceback.format_exc())