Configuring Event Notification for a Bucket
API Description
You can use this API to configure event notification for a bucket, so that you can be notified of all specified operations performed on the bucket. OBS supports event notifications through simple notification service (SMN) and the workflow of FunctionGraph.
For more information, see Event Notification
Method Definition
ObsClient.setBucketNotification(bucketName, notification)
Request Parameters
|
Field |
Type |
Optional or Mandatory |
Description |
|---|---|---|---|
|
bucketName |
str |
Mandatory |
Bucket name |
|
notification |
Optional |
Bucket event notification settings. If this parameter is left blank, the event notification configuration of the bucket is cleared. |
Returned Results
|
Type |
Description |
|---|---|
|
SDK common result object |
Sample Code
try:
from obs import Notification, TopicConfiguration,FilterRule, EventType, FunctionGraphConfiguration
fr1 = FilterRule(name='prefix', value='smn')
fr2 = FilterRule(name='suffix', value='.jpg')
topicConfiguration= TopicConfiguration(id='001',topic='your topic',events=[EventType.OBJECT_CREATED_ALL], filterRules=[fr1,fr2])
fr3 = FilterRule(name='prefix', value='function')
fr4 = FilterRule(name='suffix', value='.mp4')
functionConfiguration = FunctionGraphConfiguration(id='002', functionGraph='your function', events=[EventType.OBJECT_CREATED_ALL], filterRules=[fr3, fr4])
resp = obsClient.setBucketNotification('bucketname', Notification(topicConfigurations=[topicConfiguration], functionGraphConfigurations=[functionConfiguration]))
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: Deleting CORS Rules of a Bucket
Next Article: Obtaining the Event Notification Settings of a Bucket
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.