Configure event notification rules in Object Storage Service (OSS) to monitor objects in your buckets. When a specified event occurs — such as an object being uploaded, deleted, or replicated — OSS sends a notification to a Simple Message Queue (SMQ, formerly MNS) queue.
This tutorial walks you through an end-to-end setup:
Create two SMQ queues — one per region.
Configure a cross-region replication (CRR) rule on the source bucket.
Set up event notification rules on both buckets.
Subscribe to the auto-created topics and receive notifications.
Prerequisites
Before you begin, ensure that you have:
Two OSS buckets in different regions:
srcbucketin China (Hangzhou) anddestbucketin UK (London)Access to the SMQ console and the OSS console
A RAM role with permissions for CRR
Example scenario
Your company uses srcbucket in China (Hangzhou) to store logs and customer images in two directories:
srcbucket
└── log/
├── date1.txt
├── date2.txt
├── date3.txt
└── ...
└── destdir/
├── photo1.jpg
├── photo2.jpg
└── ...All changes to objects in log/ and destdir/ — uploads, deletions, and modifications — must be replicated to destbucket in UK (London), and all employees must be notified when those changes occur.
To meet this requirement, configure a CRR rule on srcbucket and event notification rules on both srcbucket and destbucket.
Step 1: Create SMQ queues
Create one queue per region to receive event notifications from each bucket.
Log on to the SMQ console.
In the left-side navigation pane, choose Queue Model > Queues.
In the top navigation bar, select the China (Hangzhou) region.
On the Queues page, click Create Queue. Set the queue name to
myqueue1and keep the default settings for other parameters.Click OK.
Switch to the UK (London) region in the top navigation bar and repeat the preceding steps to create a queue named
myqueue2.myqueue2receives notifications for events ondestbucket.
Step 2: Configure a CRR rule for srcbucket
Log on to the OSS console.
In the left-side navigation pane, click Buckets. On the page that appears, click srcbucket.
In the left-side navigation tree, choose Data Management > CRR.
On the CRR tab, click CRR.
In the CRR panel, configure the following parameters and click OK.
| Parameter | Value | Description |
|---|---|---|
| Destination bucket | Select UK (London), then select destbucket | The target bucket that receives replicated objects |
| Objects to replicate | Select Objects with Specified Prefix, then add prefixes destdir/ and log/ | Limits replication to only the two directories. If left blank, all objects in the bucket are replicated |
| Replication policy | Select Add/Delete/Change | Replicates object additions, deletions, and modifications |
| Replicate historical data | Select Yes | Replicates existing objects in addition to future changes |
| RAM role name | Select a role for CRR | Grants OSS permission to write objects to destbucket. If no suitable role exists, create one in the RAM console first |
Step 3: Configure event notification rules for srcbucket and destbucket
The CRR rule configured in Step 2 replicates historical data to destbucket. If the bucket contains a large amount of data, this triggers a high volume of notifications during the initial sync. Wait until historical data replication completes before setting up event notification rules.
For each bucket, configure a separate notification rule:
Log on to the OSS console.
In the left-side navigation pane, click Buckets. Select srcbucket.
In the left-side navigation tree, choose Data Processing > Event Notification.
On the Event Notification page, click Create Rule.
In the Create Rule panel, configure the parameters for
srcbucketaccording to the following table and click OK.
| Parameter | srcbucket | destbucket |
|---|---|---|
| Rule name | notification1 | notification2 |
| Event type | PutObject, CopyObject, DeleteObject, DeleteObjects | ObjectReplication:ObjectCreated, ObjectReplication:ObjectRemoved, ObjectReplication:ObjectModified |
| Resource description | Select Prefix and Suffix, then add prefixes log/ and destdir/ | Select Prefix and Suffix, then add prefixes log/ and destdir/ |
| Endpoint | Select Queue, then enter myqueue1 | Select Queue, then enter myqueue2 |
Repeat steps 2–5 for destbucket. Use the
destbucketcolumn values from the table above.
New event notification rules take about 10 minutes to take effect.
Step 4: Subscribe to topics and receive notifications
When an event matching rule is triggered, SMQ automatically creates a topic. The topic name follows the format mns-en-topics-[Product]-[RuleName]-[Timestamp] — for example, mns-en-topics-oss-notification1-1700098799.
Subscribe to each topic to start receiving notifications.
Subscribe to the topic for srcbucket
Log on to the SMQ console.
In the left-side navigation pane, click Topics.
In the top navigation bar, select the China (Hangzhou) region.
Locate the auto-created topic and click View Subscriptions in the Actions column.
In the panel that appears, click Subscriptions. On the page that appears, click Create Subscription.
In the Create Subscription panel, configure the following parameters and click OK:
Name:
mysubscription1Push type: Queue
Receiver endpoint:
myqueue1
Keep the default settings for other parameters.
Subscribe to the topic for destbucket
Switch to the UK (London) region and repeat the preceding steps to create mysubscription2. Set Push type to Queue and Receiver endpoint to myqueue2.
Receive notifications
In the left-side navigation pane, click Queues.
Locate
myqueue1and choose More > Send Messages in the Actions column.In the Receive Message section, click Receive Message. You now receive notifications when objects in the
log/anddestdir/directories ofsrcbucketare created, modified, or deleted.Repeat the preceding steps for
myqueue2to receive notifications for replication events ondestbucket.
Clean up
If you no longer need event notifications, delete the notification rules.
Deleting an event notification rule does not delete the auto-created topic. To avoid unnecessary charges, delete unused topics from the SMQ console.