• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. Developer Guide (Python SDK)
  4. Event Notification
  5. Setting Event Notification

Setting Event Notification

You can call ObsClient.setBucketNotification to set event notification for a bucket. Sample code is as follows:

# Import the module.
from com.obs.client.obs_client import ObsClient
 
# Create an instance of ObsClient.
obsClient = ObsClient(
    access_key_id='*** Provide your Access Key ***',    
    secret_access_key='*** Provide your Secret Key ***',    
    server='yourdomainname'
)
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)