Updated on 2026-09-20 GMT+08:00

Configuring Event Notifications for a Bucket (SDK for Node.js)

If you have any questions during development, post them on the Issues page of GitHub.

Function

This API is used to configure event notifications for a bucket, so that you can be notified of all specified operations performed on the bucket.

Method

ObsClient.setBucketNotification

Request Parameters

Parameter

Type

Mandatory (Yes/No)

Description

Bucket

String

Yes

Bucket name

RequestDate

String

or

Date

No

Request time

NOTE:

When the parameter type is String, the value must comply with the ISO8601 or RFC822 standard.

TopicConfigurations

Array

No

Simple Message Notification (SMN) configuration list

-

ID

String

No

SMN configuration ID

Topic

String

Yes

URN of the event notification topic. When OBS detects a specific event in the bucket, it sends a notification to the topic.

Event

Array

Yes

List of EventType for which notifications will be sent

Filter

Object

No

Filter rule information

-

FilterRules

Array

No

List of filter rules

-

Name

String

No

Whether to filter objects by object name prefix or suffix. Possible values are:

  • prefix
  • suffix

Value

String

No

Keyword used to filter objects based on the chosen prefix or suffix

Table 1 EventType

Access Method

Type

Description

EventObjectCreatedAll

ObjectCreated:*

All events for creating objects

EventObjectCreatedPut

ObjectCreated:Put

All events for uploading objects using PUT

EventObjectCreatedPost

ObjectCreated:Post

All events for uploading objects using POST

EventObjectCreatedCopy

ObjectCreated:Copy

All events for copying objects

EventObjectCreatedCompleteMultipartUpload

ObjectCreated:CompleteMultipartUpload

All events for completing multipart uploads

EventObjectRemovedAll

ObjectRemoved:*

All events for deleting objects

EventObjectRemovedDelete

ObjectRemoved:Delete

Events for deleting objects by specifying object version IDs

EventObjectRemovedDeleteMarkerCreated

ObjectRemoved:DeleteMarkerCreated

Events for deleting objects without specifying object version IDs after versioning is enabled

Sample Code 1: Enabling Event Notifications

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

// Import the OBS library.
// Use npm for installation.
var ObsClient = require('esdk-obs-nodejs');
// Use the source code for installation.
// var ObsClient = require('./lib/obs');

// Create an ObsClient instance.
const obsClient = new ObsClient({
    //Obtain an AK and SK pair using environment variables or import an AK and SK pair in other ways. Using hard coding may result in leakage.
    //Obtain an AK/SK pair on the management console. For details, see https://support.huaweicloud.com/intl/en-us/usermanual-ca/ca_01_0003.html.
    access_key_id: process.env.ACCESS_KEY_ID,
    secret_access_key: process.env.SECRET_ACCESS_KEY,
    //CN-Hong Kong is used here as an example. Replace it with the one currently in use.
    server: 'https://obs.ap-southeast-1.myhuaweicloud.com'
    
});

obsClient.setBucketNotification({
       Bucket: 'bucketname',
       TopicConfigurations : [
           {
                ID : 'id1',
                Topic : 'your topic URN',
                Event : [obsClient.enums.EventObjectCreatedAll],
                Filter : {
                     FilterRules :[{Name : 'prefix', Value: 'smn'}, {Name : 'suffix', Value: '.jpg'}]
                }
            }
       ],
}, (err, result) => {
       if(err){
              console.log('Error-->' + err);
       }else{
              console.log('Status-->' + result.CommonMsg.Status);
       }
});

Use TopicConfigurations to specify SMN configurations.

Sample Code 2: Disabling Event Notifications

You can disable event notifications for a bucket by calling ObsClient.setBucketNotification to clear the event notification configuration. Sample code is as follows:

// Import the OBS library.
// Use npm for installation.
var ObsClient = require('esdk-obs-nodejs');
// Use the source code for installation.
// var ObsClient = require('./lib/obs');

// Create an ObsClient instance.
const obsClient = new ObsClient({
    //Obtain an AK and SK pair using environment variables or import an AK and SK pair in other ways. Using hard coding may result in leakage.
    //Obtain an AK/SK pair on the management console. For details, see https://support.huaweicloud.com/intl/en-us/usermanual-ca/ca_01_0003.html.
    access_key_id: process.env.ACCESS_KEY_ID,
    secret_access_key: process.env.SECRET_ACCESS_KEY,
    //CN-Hong Kong is used here as an example. Replace it with the one currently in use.
    server: 'https://obs.ap-southeast-1.myhuaweicloud.com'
    
});

obsClient.setBucketNotification({
       Bucket: 'bucketname',
       TopicConfigurations : []
}, (err, result) => {
       if(err){
              console.log('Error-->' + err);
       }else{
              console.log('Status-->' + result.CommonMsg.Status);
       }
});