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 the functions by 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. For more information, see Configure an EventBridge-based OSS trigger.
Regular expression matching is not supported for the object prefixes and suffixes that you configure for native OSS triggers and EventBridge-based OSS triggers. For more information, see Configure a native OSS trigger and Configure an EventBridge-based OSS trigger.
If you want to associate more than 10 OSS triggers with a bucket, you can use only EventBridge-based OSS triggers. For more information, see Configure an EventBridge-based OSS trigger.
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 the Event notifications section of the "Overview" topic.
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 InitiateMultipartUpload operation is called to initiate a multipart upload task in OSS. Before you use multipart upload to upload data, you must call the InitiateMultipartUpload operation. 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. Note The event is supported in the following regions: China (Hangzhou), China (Shanghai), China (Beijing), and China (Shenzhen). |
oss:ObjectReplication:ObjectModified | An object is overwritten in a data replication task. Note The event is supported in the following regions: China (Hangzhou), China (Shanghai), China (Beijing), and China (Shenzhen). | |
oss:ObjectReplication:ObjectRemoved | An object is deleted in a data replication task. Note The event is supported in the following regions: China (Hangzhou), China (Shanghai), China (Beijing), and China (Shenzhen). |
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.
Ensure semantic uniqueness of native OSS triggers
The configuration semantics of a trigger must be unique within the bucket for which the trigger is created. The configurations include the Trigger Event parameter, the Object Prefix parameter, and the Object Suffix parameter. For example, you create a trigger whose trigger event is oss:ObjectCreated:PutObject for a bucket. The Object Prefix parameter is set to source and the Object Suffix parameter is set to zip for the trigger. The following table describes whether new triggers of different configurations are valid for the bucket.
Trigger event | Object Prefix | Object Suffix | Valid | Description |
oss:ObjectCreated:* | source1 | zip1 | No | The event type of the new trigger conflicts with that of the existing trigger. Note oss:ObjectCreated:* includes all ObjectCreated events. If you have created a trigger of the ObjectCreated event type in a bucket, you cannot create a trigger of the oss:ObjectCreated:* event type. Similarly, if you have created a trigger of the oss:ObjectCreated:* event type in a bucket, you cannot create a trigger of the ObjectCreated event type. |
oss:ObjectCreated:PutObject | source | zip | No | The values of the Object Prefix and Object Suffix parameters of the new trigger are the same as those of the existing trigger. |
source | None | No | The value of the Object Prefix parameter of the new trigger is the same as that of the existing trigger. If you do not configure the Object Suffix parameter, objects with the zip suffix are included. | |
None | zip | No | The value of the Object Suffix parameter of the new trigger is the same as that of the existing trigger. If you do not configure the Object Prefix parameter, objects with the source prefix are included. | |
source1 | zip1 | Yes | The values of the Object Prefix and Object Suffix parameters of the new trigger are different from those of the existing trigger. | |
source | zip1 | Yes | The value of the Object Suffix parameter of the new trigger is different from that of the existing trigger. | |
source1 | zip | Yes | The value of the Object Prefix parameter of the new trigger is different from that of the existing trigger. | |
oss:ObjectCreated:PostObject | source | zip | Yes | The value of the Trigger Event parameter of the new trigger is different from that of the existing trigger. |
Semantic uniqueness must be ensured for native OSS triggers. Therefore, you cannot configure the same OSS trigger for different functions.
If you want to configure the same OSS trigger for different functions for the same event type, you can configure EventBridge-based OSS triggers. For more information, see Configure an EventBridge-based OSS trigger.
References
More information
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.
Triggers
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 Log records.
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?