Updated on 2026-08-03 GMT+08:00

Setting an Event Notification

If you have any questions during development, post them on the Issues page of GitHub. For details about parameters and usage of each API, see API Reference.

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

// Import the dependency library.
require 'vendor/autoload.php';
// Import the SDK code library during the installation with source code.
// require 'obs-autoloader.php';
// Declare the namespace.
use Obs\ObsClient;
// Create an ObsClient instance.
$obsClient = new ObsClient ( [ 
      //Obtain an AK/SK pair using environment variables or import the AK/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.      'key' => getenv('ACCESS_KEY_ID'),
      'secret' => getenv('SECRET_ACCESS_KEY'),
      'endpoint' => 'https://your-endpoint'
] );

$resp = $obsClient->setBucketNotification ( [ 
       'Bucket' => 'bucketname',
       'TopicConfigurations' => [ 
            [
                'ID' => '001',
                // Set parameter Topic to a value in the urn:smn:region:project_id:smn_topic format. The following is an example:
                'Topic' => 'urn:smn:exampleRegion:d745b885f14941369b2d2138e7a65bef:obs_test',
                'Event' => [ 
                          ObsClient::ObjectCreatedAll 
                ],
                'Filter' => [ 
                       [ 
                                  'Name' => 'prefix',
                                  'Value' => 'smn' 
                       ],
                       [ 
                                  'Name' => 'suffix',
                                  'Value' => '.jpg' 
                       ] 
                ]
           ] 
       ] 
] );
printf ( "RequestId:%s\n", $resp ['RequestId'] );

The Topic parameter is described as follows:

It indicates the URN of the event notification topic. When OBS detects specific events in a bucket, it publishes a notification message to this topic. You can find the topic's URN on the Topics page of the SMN console.

Use the TopicConfigurations parameter to configure the event notification for a bucket.