When you integrate Object Storage Service (OSS) with Function Compute, you can use OSS events to trigger function execution and process data in OSS. This topic describes the limits, event types, and trigger rules for OSS triggers in Function Compute.
Background information
OSS integrates seamlessly with Function Compute using OSS triggers. You can write functions to process OSS events. When OSS captures an event of a specified type, the associated function is executed. For example, you can configure a function to process PutObject events. When you call the OSS PutObject operation to upload an image to OSS, the associated function is automatically triggered to process the image.
When OSS is integrated with Function Compute, you can use various functions to process image or audio data and store the results in multiple storage services. In this architecture, you only need to focus on writing the function logic. The system processes large amounts of data in real time, reliably, and at scale.
OSS trigger limits
You can configure multiple file prefixes and suffixes only for EventBridge-based OSS triggers.
Regular expression matching is not supported for the file prefixes and suffixes that you configure for native OSS triggers and EventBridge-based OSS triggers.
Only EventBridge-based OSS triggers support associating more than 10 OSS triggers with a single bucket.
In general, do not associate more than 10 triggers with a single bucket. Instead, create a new bucket and create triggers for it.
OSS event definition
When the OSS system captures a specified event, it encodes the event information into a JSON string and passes it to the handling function. For more information about the format of OSS event notifications, see Event notifications.
The following table describes the supported OSS events. An event type corresponds to an API operation, such as ObjectCreated, ObjectRemoved, or ObjectModified. When an API operation is called and successfully executed, it triggers the function to run once.
Event type | Event name | Description |
ObjectCreated | oss:ObjectCreated:PutObject | Call the PutObject operation to upload a file. For more information, see PutObject. |
oss:ObjectCreated:PutSymlink | Call the PutSymlink operation to create a symbolic link for a target object in OSS. You can use this symbolic link to access the target object. For more information, see PutSymlink. | |
oss:ObjectCreated:PostObject | Call the PostObject operation to upload a file to a specified bucket using an HTML form. For more information, see PostObject. | |
oss:ObjectCreated:CopyObject | Call the CopyObject operation to copy an existing object in OSS. For more information, see CopyObject. | |
oss:ObjectCreated:InitiateMultipartUpload | Before you transfer data in MultipartUpload mode, you must call the InitiateMultipartUpload operation to notify OSS to initialize a multipart upload event. For more information, see InitiateMultipartUpload. | |
oss:ObjectCreated:UploadPart | After a multipart upload event is initiated, you can upload data in parts based on the specified object name and upload ID. For more information, see UploadPart. | |
oss:ObjectCreated:UploadPartCopy | UploadPartCopy uploads a part by copying data from an existing object. For more information, see UploadPartCopy. | |
oss:ObjectCreated:CompleteMultipartUpload | After all data parts are uploaded, you must call the CompleteMultipartUpload operation to complete the multipart upload of the entire file. For more information, see CompleteMultipartUpload. | |
oss:ObjectCreated:AppendObject | Call the AppendObject operation to upload a file by appending data. For more information, see AppendObject. | |
oss:ObjectCreated:* | The function is triggered after any of the preceding ObjectCreated API operations are successfully called. | |
ObjectRemoved | oss:ObjectRemoved:DeleteObject | Call the DeleteObject operation to delete an object. For more information, see DeleteObject. |
oss:ObjectRemoved:DeleteObjects | Call the DeleteMultipleObjects operation to delete multiple files in a batch. For more information, see DeleteMultipleObjects. | |
oss:ObjectRemoved:AbortMultipartUpload | Call the AbortMultipartUpload operation to stop a multipart upload event based on the provided upload ID. For more information, see AbortMultipartUpload. | |
ObjectModified | oss:ObjectModified:UpdateObjectMeta | Call the UpdateObjectMeta operation to modify the properties of an object. Note This event is supported in the following regions: China (Hangzhou), China (Shanghai), China (Qingdao), China (Beijing), China (Zhangjiakou), China (Hohhot), China (Shenzhen), and China (Chengdu). |
ObjectReplication | oss:ObjectReplication:ObjectCreated | A write operation involved in a data replication process. |
oss:ObjectReplication:ObjectModified | An overwrite operation involved in a data replication process. | |
oss:ObjectReplication:ObjectRemoved | A delete operation involved in a data replication process. |
OSS trigger rules
Avoid loop triggering
When you use OSS triggers, avoid creating trigger loops. A typical loop-triggering scenario occurs when a file upload event in an OSS bucket triggers a function. After the function is executed, it generates one or more files and writes them to the same OSS bucket. This write action triggers the function again, which creates a loop.
To avoid unnecessary costs that result from loop triggering, you can configure a file prefix or suffix. For example, you can set the file prefix for the triggering file to src and the file prefix for the generated file to dst. In this case, the generated file does not trigger the function again. If you do not set a file prefix or suffix, files with any prefix or suffix are matched. For more information, see Step 1: Create an OSS trigger.
Configuration rules for native OSS triggers
To prevent the creation of duplicate triggers in the same bucket, which can cause a single event to activate multiple triggers, Function Compute requires that the trigger configurations in a bucket meet the following conditions:
The combination of the triggering event, file prefix, and file suffix must be unique.
A new trigger can be created only if its combination of triggering event, file prefix, and file suffix does not conflict with an existing trigger.
The following table provides examples of the configuration rules for native OSS triggers.
Existing trigger | New trigger | Creation successful? | Description | ||||
Triggering event | File prefix | File suffix | Triggering event | File prefix | File suffix | ||
oss:ObjectCreated:PutObject | source | zip | oss:ObjectCreated:* | source | zip | Failed | oss:ObjectCreated:* is a superset of all ObjectCreated event types. The event oss:ObjectCreated:* of the new trigger matches the event oss:ObjectCreated:PutObject of the existing trigger that has the same file prefix and suffix. |
source1 | zip1 | Success | The event type and File prefix of the new trigger match those of the existing trigger, but the File suffix does not match. | ||||
oss:ObjectCreated:PutObject | source | zip | Failed | The event type, File prefix, and File suffix of the new trigger all match those of the existing trigger. | |||
source | 1zip | Failed | |||||
source1 | zip | Failed | |||||
source | None | Failed | The event type and File prefix of the new trigger match those of the existing trigger. If the File suffix is not set, it includes objects with the zip suffix. This means the File suffix also matches. | ||||
None | zip | No | The event type and File suffix of the new trigger match those of the existing trigger. If the File prefix is not set, it includes objects with the source prefix. This means the File prefix also matches. | ||||
source1 | zip1 | Success | The event type and File prefix of the new trigger match those of the existing trigger, but the File suffix does not match. | ||||
1source | 1zip | Success | The event type and File suffix of the new trigger match those of the existing trigger, but the File prefix does not match. | ||||
oss:ObjectCreated:PostObject | source | zip | Success | The event type of the new trigger does not match that of the existing trigger. | |||
File prefixes are matched from the start of the object name, and file suffixes are matched from the end.
The following sections describe two types of conflicts. A new trigger cannot be created if both types of conflicts exist. A new trigger can be created if only one or neither of the conflicts exist.
Event type conflict
Existing trigger event type | New trigger event type | Conflict description |
|
|
|
|
|
Path matching conflict
Existing trigger path | New trigger path | Conflict description |
|
| Prefix does not match, suffix matches. No path conflict. |
|
| Prefix matches, suffix does not match. No path conflict. |
|
| Prefix matches, suffix matches. Path conflict. |
If you want to use the same OSS event type to trigger different functions for different processing tasks, you can create an EventBridge-based OSS trigger.
FAQ
References
Configure triggers
For more information about how to configure and use native OSS triggers and EventBridge-based OSS triggers, see Configure a native OSS trigger and Configure an EventBridge-based OSS trigger.
Questions about triggers
If you want to check which event executed a function, you can print event type logs from your code logic. For more information, see Log records.
If you want to call another function from within a function, you can use an API to call the function. For more information, see Can functions call each other?