Object Storage Service (OSS) triggers let Function Compute run your functions automatically when OSS events occur. When an object is created, deleted, modified, or replicated in a bucket, OSS fires an event that invokes the associated function. This enables real-time, event-driven processing of images, audio, logs, and other data at scale -- without managing infrastructure.
For example, uploading an image through the PutObject operation can trigger a function that generates thumbnails and stores them in another bucket.
How it works
An OSS event occurs in a bucket (for example, a file upload or deletion).
OSS encodes the event as a JSON string and passes it to the associated function. For the event payload format, see Event notifications.
Function Compute runs the function and returns the result.
Native and EventBridge-based triggers
Function Compute supports two types of OSS triggers. Choose the type that fits your use case.
| Capability | Native OSS trigger | EventBridge-based OSS trigger |
|---|---|---|
| Multiple file prefixes and suffixes per trigger | Not supported | Supported |
| More than 10 triggers per bucket | Not supported | Supported |
| Same event type triggering different functions | Not supported | Supported |
| Regular expression matching for prefix/suffix | Not supported | Not supported |
For native OSS triggers, do not associate more than 10 triggers with a single bucket. Create a new bucket and set up triggers for it instead.
Supported event types
Each event type maps to an OSS API operation. When the operation completes, the function runs once.
ObjectCreated
Triggered when objects are added to a bucket.
| Event name | API operation | Description |
|---|---|---|
oss:ObjectCreated:PutObject | PutObject | Upload an object |
oss:ObjectCreated:PostObject | PostObject | Upload an object through an HTML form |
oss:ObjectCreated:CopyObject | CopyObject | Copy an existing object |
oss:ObjectCreated:PutSymlink | PutSymlink | Create a symbolic link to a target object |
oss:ObjectCreated:AppendObject | AppendObject | Upload an object by appending data |
oss:ObjectCreated:InitiateMultipartUpload | InitiateMultipartUpload | Initialize a multipart upload |
oss:ObjectCreated:UploadPart | UploadPart | Upload a part in a multipart upload |
oss:ObjectCreated:UploadPartCopy | UploadPartCopy | Upload a part by copying from an existing object |
oss:ObjectCreated:CompleteMultipartUpload | CompleteMultipartUpload | Complete a multipart upload |
oss:ObjectCreated:* | All of the above | Any ObjectCreated operation |
ObjectRemoved
Triggered when objects are removed from a bucket.
| Event name | API operation | Description |
|---|---|---|
oss:ObjectRemoved:DeleteObject | DeleteObject | Delete a single object |
oss:ObjectRemoved:DeleteObjects | DeleteMultipleObjects | Delete multiple objects in a batch |
oss:ObjectRemoved:AbortMultipartUpload | AbortMultipartUpload | Abort a multipart upload |
ObjectModified
Triggered when object metadata is updated.
| Event name | API operation | Description |
|---|---|---|
oss:ObjectModified:UpdateObjectMeta | UpdateObjectMeta | Modify the properties of an object |
This event is supported only in the following regions: China (Hangzhou), China (Shanghai), China (Qingdao), China (Beijing), China (Zhangjiakou), China (Hohhot), China (Shenzhen), and China (Chengdu).
ObjectReplication
Triggered during data replication operations.
| Event name | Description |
|---|---|
oss:ObjectReplication:ObjectCreated | A write operation during data replication |
oss:ObjectReplication:ObjectModified | An overwrite operation during data replication |
oss:ObjectReplication:ObjectRemoved | A delete operation during data replication |
Avoid loop triggering
Writing function output back to the same bucket that triggered the function creates an infinite loop. Each write triggers the function again, which generates more writes, leading to runaway invocations and costs.
Prevention: Use different file prefixes for input and output. For example, set the file prefix of the triggering object to src and the prefix of the generated output to dst. This way, output files do not match the trigger condition.
If no file prefix or suffix is configured, the trigger matches all objects in the bucket. For details, see Step 1: Create an OSS trigger.
Trigger conflict rules for native OSS triggers
Within a bucket, each native OSS trigger must have a unique combination of event type, file prefix, and file suffix. A new trigger can only be created if its combination does not conflict with an existing trigger.
A conflict exists when both of the following conditions are true:
Event type conflict -- The event types overlap. For example,
oss:ObjectCreated:PutObjectconflicts withoss:ObjectCreated:*because the wildcard is a superset of the specific event.Path matching conflict -- Both the file prefix and file suffix match. Prefixes are matched from the start of the object name; suffixes are matched from the end.
If only one condition is true, there is no conflict and the trigger can be created.
Event type conflict
| Existing trigger event type | New trigger event type | Conflict? |
|---|---|---|
oss:ObjectCreated:PutObject | oss:ObjectCreated:* | Yes. The wildcard includes PutObject. |
oss:ObjectCreated:* | oss:ObjectCreated:PostObject | Yes. The wildcard includes PostObject. |
oss:ObjectCreated:PutObject | oss:ObjectCreated:PostObject | No. Different specific event types. |
Path matching conflict
| Existing trigger path | New trigger path | Conflict? |
|---|---|---|
Prefix: source, Suffix: .zip | Prefix: 1source, Suffix: .zip | No. Prefix does not match. |
Prefix: source, Suffix: .zip | Prefix: source, Suffix: .zip1 | No. Suffix does not match. |
Prefix: source, Suffix: .zip | Prefix: source, Suffix: .zip | Yes. Both prefix and suffix match. |
If the file prefix or file suffix is not set, it matches objects with any prefix or suffix. For example, if a new trigger has event type oss:ObjectCreated:PutObject, prefix source, and no suffix, it conflicts with an existing trigger that has event type oss:ObjectCreated:PutObject, prefix source, and suffix .zip -- because the empty suffix matches all suffixes, including .zip.
Configuration examples
The following table shows whether a new native OSS trigger can be created alongside an existing trigger with event type oss:ObjectCreated:PutObject, file prefix source, and file suffix zip.
| New trigger event type | New file prefix | New file suffix | Result | Reason |
|---|---|---|---|---|
oss:ObjectCreated:* | source | zip | Failed | Event type conflict (wildcard includes PutObject) and path conflict (same prefix and suffix). |
oss:ObjectCreated:PutObject | source1 | zip1 | Success | Same event type, but different prefix and suffix -- no path conflict. |
oss:ObjectCreated:PutObject | source | zip | Failed | Same event type and same prefix/suffix -- both conflicts exist. |
oss:ObjectCreated:PutObject | source | 1zip | Failed | Same event type; prefix matches, and 1zip ends with zip, so the suffix also matches. |
oss:ObjectCreated:PutObject | source1 | zip | Failed | Same event type; suffix matches, and source1 starts with source, so the prefix also matches. |
oss:ObjectCreated:PutObject | source | (none) | Failed | Same event type; prefix matches, and an empty suffix matches all suffixes including zip. |
oss:ObjectCreated:PutObject | (none) | zip | Failed | Same event type; suffix matches, and an empty prefix matches all prefixes including source. |
oss:ObjectCreated:PutObject | source1 | zip1 | Success | Same event type, but different prefix and suffix. |
oss:ObjectCreated:PutObject | 1source | 1zip | Success | Same event type, but different prefix and suffix. |
oss:ObjectCreated:PostObject | source | zip | Success | Different event type -- no event type conflict. |
To use the same OSS event type to trigger different functions for different processing tasks, create an EventBridge-based OSS trigger.
FAQ
References
Configure triggers: Configure a native OSS trigger | Configure an EventBridge-based OSS trigger
Log event types: To check which event triggered a function, print the event type in your function code. See Log records.
Call functions from functions: See Can functions call each other?