After you integrate Object Storage Service (OSS) with Function Compute, OSS events can trigger the execution of functions to process data in OSS buckets. This topic describes limits, event types, and trigger rules of OSS triggers in Function Compute.
Background information
OSS can be seamlessly integrated with Function Compute by using OSS triggers. You can write functions and invoke them using OSS events. When OSS captures an event of a specified type, the associated function is executed. For example, you can write a function to process PutObject events. When you call the PutObject operation of OSS to upload an image to OSS, the function is automatically invoked to process the image.
After OSS is integrated with Function Compute, you can invoke various functions to process images and audio files, and write processed files to specific storage services. In the entire process, you need only to focus on writing the function logic. Function Compute can process large amounts of data in real time and in parallel.
Limits on OSS triggers
You can configure multiple object prefixes and suffixes only for EventBridge-based OSS triggers.
Regular expression matching is not supported for the object prefixes and suffixes that you configure for native OSS triggers and EventBridge-based OSS triggers.
If you want to associate more than 10 OSS triggers with a bucket, you can use only EventBridge-based OSS triggers.
We recommend that you do not associate more than 10 triggers with a bucket. If you want to associate more triggers, you can create a new bucket and create new triggers based on the new bucket.
OSS events
When OSS captures an event of the specified type, OSS encodes the event information as a JSON string and passes the JSON string to the function that processes the event. For more information about the format of OSS event notification, see Event notifications.
The following table describes the types of OSS events that are supported by Function Compute. Each event type corresponds to an ObjectCreated, ObjectRemoved, or ObjectModified operation. After an operation is called as expected, the function is triggered and executed once.
Event type | Event | Description |
ObjectCreated | oss:ObjectCreated:PutObject | The PutObject operation is called to upload an object. For more information, see PutObject. |
oss:ObjectCreated:PutSymlink | The PutSymlink operation is called to create a symbolic link for a destination object in OSS. The symbolic link can be used to access the destination object. For more information, see PutSymlink. | |
oss:ObjectCreated:PostObject | The PostObject operation is called to upload a file to a specified bucket by using an HTML form. For more information, see PostObject. | |
oss:ObjectCreated:CopyObject | The CopyObject operation is called to copy an existing object in OSS. For more information, see CopyObject. | |
oss:ObjectCreated:InitiateMultipartUpload | The MultipartUpload mode is used to upload data. Before you use multipart upload to upload data, you must call the InitiateMultipartUpload operation to initiate a multipart upload task in OSS. For more information, see InitiateMultipartUpload. | |
oss:ObjectCreated:UploadPart | After the multipart upload event is initiated, you can upload data in parts based on specified object names and upload IDs. For more information, see UploadPart. | |
oss:ObjectCreated:UploadPartCopy | The UploadPartCopy operation is called to copy data from an existing object to upload a part. For more information, see UploadPartCopy. | |
oss:ObjectCreated:CompleteMultipartUpload | The CompleteMultipartUpload operation is called to complete the multipart upload task of an object. For more information, see CompleteMultipartUpload. | |
oss:ObjectCreated:AppendObject | The AppendObject operation is called to upload an object by appending the content of the object to an existing object. For more information, see AppendObject. | |
oss:ObjectCreated:* | One of the preceding API operations of the ObjectCreated type is called. | |
ObjectRemoved | oss:ObjectRemoved:DeleteObject | The DeleteObject operation is called to delete an object. For more information, see DeleteObject. |
oss:ObjectRemoved:DeleteObjects | The DeleteMultipleObjects operation is called to delete multiple objects at a time. For more information, see DeleteMultipleObjects. | |
oss:ObjectRemoved:AbortMultipartUpload | The AbortMultipartUpload operation is called to cancel a multipart upload task based on the specified upload ID. For more information, see AbortMultipartUpload. | |
ObjectModified | oss:ObjectModified:UpdateObjectMeta | The UpdateObjectMeta operation is called to modify the attributes of an object. Note This type of 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 | An object is created in a data replication task. |
oss:ObjectReplication:ObjectModified | An object is overwritten in a data replication task. | |
oss:ObjectReplication:ObjectRemoved | An object is deleted in a data replication task. |
Triggering rules
Do not perform loop triggering
When you use OSS triggers, do not perform loop triggering. For example, when you upload objects to an OSS bucket, the upload operation invokes a function. The function generates one or more objects that are written to the OSS bucket, and the write operation invokes the function again. This results in a loop.
To prevent extra costs caused by loop triggering, we recommend that you configure Object Prefix or Object Suffix when you create an OSS trigger. For example, you can set Object Prefix to src
and Object Prefix to dst
. This way, generated objects do not invoke the function again. If you do not configure Object Prefix or Object Suffix, objects with all prefixes and suffixes 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 for the same bucket, which could cause a single event to trigger multiple triggers, Function Compute requires that trigger configurations for a single bucket meet the following conditions:
The combination of trigger event, object prefix, and object suffix must be unique.
A new trigger can be successfully created only if its "trigger event + object prefix + object suffix" combination does not conflict with existing triggers.
The following example illustrates the configuration rules for native OSS triggers:
Existing trigger | New trigger | Is the new trigger valid? | Description | ||||
Trigger Event | Object Prefix | Object Suffix | Trigger Event | Object Prefix | Object Suffix | ||
oss:ObjectCreated:PutObject | source | zip | oss:ObjectCreated:* | source | zip | No | oss:ObjectCreated:* includes all ObjectCreated events. The event oss:ObjectCreated:* of the new trigger matches the event oss:ObjectCreated:PutObject of the existing trigger with the same object prefix and suffix. |
source1 | zip1 | Yes | The event type and Object Prefix of the new trigger match those of the existing trigger, but the Object Suffix does not match. | ||||
oss:ObjectCreated:PutObject | source | zip | No | The event type, Object Prefix, and Object Suffix of the new trigger all match those of the existing trigger. | |||
source | 1zip | No | |||||
source1 | zip | No | |||||
source | None | No | The event type and Object Prefix of the new trigger match those of the existing trigger. If Object Suffix is not set, it includes objects with the suffix "zip", which means the Object Suffix also matches. | ||||
None | zip | No | The event type and Object Suffix of the new trigger match those of the existing trigger. If Object Prefix is not set, it includes objects with the prefix "source", which means the Object Prefix also matches. | ||||
source1 | zip1 | Yes | The event type of the new trigger matches that of the existing trigger, but the Object Prefix and Object Suffix do not match. | ||||
1source | 1zip | Yes | The event type of the new trigger matches that of the existing trigger, but the Object Prefix and Object Suffix do not match. | ||||
oss:ObjectCreated:PostObject | source | zip | Yes | The event type of the new trigger does not match that of the existing trigger. |
Object prefix matching follows a forward matching principle, and object suffix matching follows a backward matching principle.
The following describes two types of conflicts. If both conflicts exist, the new trigger cannot be created. If neither conflict exists or only one conflict exists, the new trigger can be created.
Event type conflict
Event type of existing trigger | Event type of new trigger | Conflict description |
|
|
|
|
|
Path matching conflict
Path of existing trigger | Path of new trigger | 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 exists |
If you want to configure the same OSS trigger for different functions for the same event type, you can configure EventBridge-based OSS triggers.
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.
Trigger-related issues
If you want to check which event triggers a function, you can configure the system to print event type logs in your code. For more information, see Logs.
If you want to use a function to invoke another function, you can specify an API operation to invoke the function. For more information, see Can functions invoke each other?.