Configuring Event Notifications for a Bucket (SDK for Python)
Function
You can configure notifications for certain types of events. When such events happen in your bucket, you will be notified of the operations in a timely manner.
This API configures event notifications for a bucket.
Restrictions
- To configure event notifications for a bucket, you must be the bucket owner or have the required permission (obs:bucket:PutBucketNotification in IAM or PutBucketNotification in a bucket policy). For details, see Introduction to OBS Access Control, IAM Custom Policies, and Creating a Custom Bucket Policy.
- The mapping between OBS regions and endpoints must comply with what is listed in Regions and Endpoints.
Method
ObsClient.setBucketNotification(bucketName, notification, extensionHeaders)
Request Parameters
| Parameter | Type | Mandatory (Yes/No) | Description |
|---|---|---|---|
| bucketName | str | Yes | Explanation: Bucket name Restrictions:
Default value: None |
| notification | No | Explanation: Event notification configurations If this parameter is left blank, there is no event notification configured. For details, see Table 1. Default value: None | |
| extensionHeaders | dict | No | Explanation: Extension headers. Value range: See User-defined Headers (SDK for Python). Default value: None |
| Parameter | Type | Mandatory (Yes/No) | Description |
|---|---|---|---|
| id | str | No if used as a request parameter | Event notification setting ID |
| topic | str | Yes if used as a request parameter | URN of the event notification topic. After detecting a specific event, OBS sends a message to the topic. |
| events | list of str | Yes if used as a request parameter | Event types for which a notification needs to be sent |
| filterRules | list of FilterRule | No if used as a request parameter | List of filtering rules |
| Constant | Description |
|---|---|
| OBJECT_CREATED_ALL | All events for creating objects, including uploading objects through PUT and POST, copying objects, and combining parts |
| OBJECT_CREATED_PUT | PUT Object events |
| OBJECT_CREATED_POST | POST Object events |
| OBJECT_CREATED_COPY | Object copying events |
| OBJECT_CREATED_COMPLETE_MULTIPART_UPLOAD | Parts merging events |
| OBJECT_REMOVED_ALL | Events of calling the APIs for deletion and aborting multipart uploads Events for deleting objects without specifying object version IDs, when versioning is enabled, as well as deleting objects by specifying object version IDs |
| OBJECT_REMOVED_DELETE | Events for deleting objects by specifying object version IDs |
| OBJECT_REMOVED_DELETE_MARKER_CREATED | Events for deleting objects without specifying object version IDs, when versioning is enabled |
| Parameter | Type | Mandatory (Yes/No) | Description |
|---|---|---|---|
| name | str | No if used as a request parameter | Prefix or suffix of object names for filtering. Possible values are:
|
| value | str | No if used as a request parameter | Keyword of object names for filtering objects by prefix or suffix |
Responses
| Type | Description |
|---|---|
| Explanation: SDK common results |
| Parameter | Type | Description |
|---|---|---|
| status | int | Explanation: HTTP status code Value range: A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). For more information, see Status Code. Default value: None |
| reason | str | Explanation: Reason description Default value: None |
| errorCode | str | Explanation: Error code returned by the OBS server. If the value of status is less than 300, this parameter is left blank. Default value: None |
| errorMessage | str | Explanation: Error message returned by the OBS server. If the value of status is less than 300, this parameter is left blank. Default value: None |
| requestId | str | Explanation: Request ID returned by the OBS server Default value: None |
| indicator | str | Explanation: Error indicator returned by the OBS server Default value: None |
| hostId | str | Explanation: Requested server ID. If the value of status is less than 300, this parameter is left blank. Default value: None |
| resource | str | Explanation: Error source (a bucket or an object). If the value of status is less than 300, this parameter is left blank. Default value: None |
| header | list | Explanation: Response header list, composed of tuples. Each tuple consists of two elements, respectively corresponding to the key and value of a response header. Default value: None |
| body | object | Explanation: Result content returned after the operation is successful. If the value of status is larger than 300, this parameter is left blank. The value varies with the API being called. For details, see the sections "Bucket-Related APIs" and "Object-Related APIs". Default value: None |
Code Examples
try:
from obs import Notification, TopicConfiguration,FilterRule, EventType
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])
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()) Helpful Links
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot