• Object Storage Service

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

PUT Bucket notification

API Description

You can use this API to configure event notification for a bucket. You will be notified of all specified operations performed on the bucket.

Method Definition

ObsClient.setBucketNotification(bucketName, notification)

Request Parameter

Field

Type

Optional or Mandatory

Description

bucketName

str

Mandatory

Bucket name

notification

Notification

Optional

Bucket event notification settings

Returned Result

Type

Description

GetResult

SDK common result object

Sample Code

try:
    from com.obs.models.notification import Notification, TopicConfiguration,FilterRule 
     
    fr1 = FilterRule(name='prefix', value='smn') 
    fr2 = FilterRule(name='suffix', value='.jpg') 
    topicConfiguration= TopicConfiguration(id='001',topic='urn:smn:region:xxxx:topic1',events=['s3:ObjectCreated:*'], filterRules=[fr1,fr2]) 
     
    resp = obsClient.setBucketNotification('bucketname', Notification(topicConfigurations=[topicConfiguration])) 
      
    if resp.status < 300: 
        print('requestId:', resp.requestId) 
    else: 
        print('errorCode:', resp.errorCode) 
        print('errorMessage:', resp.errorMessage)
except:
    import traceback
    print(traceback.format_exc())