Object Storage Service (OSS) is a secure, cost-effective, and highly reliable cloud storage service that is provided by Alibaba Cloud. OSS allows you to store a large amount of data in the cloud. After you integrate OSS with Function Compute, OSS events can trigger the execution of functions to process data in OSS buckets.

Background information

OSS is seamlessly integrated with Function Compute by using OSS event triggers. You can write functions and trigger the functions by using OSS events. When OSS captures an event of a specified type, the event triggers the execution of the corresponding function. 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 triggered to process the image.

After OSS is integrated with Function Compute, you can invoke various functions to process images and audio data and write the results to multiple storage services. In the entire process, you need to only focus on writing the function logic. Function Compute can process large amounts of data in real time and in parallel.

OSS events

When OSS captures an event, 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 notifications, see Notifications.

The following table describes the supported OSS events. Each type of event corresponds to an ObjectCreated or ObjectRemoved operation. After an operation is called as expected, the function is triggered and executed once.

Event name Description
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. You can use this symbolic link 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 Before you use multipart upload to upload data, you must call the InitiateMultipartUpload operation to notify OSS to initiate a multipart upload event. For more information, see InitiateMultipartUpload.
oss:ObjectCreated:UploadPart After you initialize the multipart upload event, 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 You must call the CompleteMultipartUpload operation to finish the multipart upload 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:* A function is triggered when one of the preceding ObjectCreated operations is called.
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 You can call the AbortMultipartUpload operation to cancel a multipart upload task based on the specified upload ID. For more information, see AbortMultipartUpload.
Note You can create up to 10 triggers in a bucket.

Trigger rules

Avoid loop invocation

Warning When you use OSS event triggers, you must prevent loops. For example, when objects are uploaded to an OSS bucket, the upload operation triggers a function. Then, this function generates one or more objects to be written to the OSS bucket, and the write operation triggers this function again. This results in a loop.

To prevent unnecessary fees generated for triggering a function in a loop, we recommend that you set the Object Prefix or Object Suffix parameter when you create an OSS event trigger. For example, if you want the objects with the src prefix to trigger the function, you can set the Object Prefix parameter to src and the prefix of the objects generated after the function is executed to dst. This way, the generated objects do not trigger the function again. If you do not specify the Object Prefix or Object Suffix parameter, objects with all prefixes and suffixes are matched.

Ensure the semantic uniqueness

The semantics of the configurations of triggers that are created in a bucket must be unique. The configurations include the Trigger Event, Object Prefix, and Object Suffix parameters. For example, you have created a trigger whose trigger event is oss:ObjectCreated:PutObject for a bucket. The Object Prefix and Object Suffix parameters of the trigger are set to source and zip. The following table describes whether new triggers for the bucket are valid.

Trigger Event Object Prefix Object Suffix Valid Description
oss:ObjectCreated:* source1 zip1 No The new trigger is configured with the same type of event as 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.
oss:ObjectCreated:PutObject source zip No The new trigger is configured with the same values for the Object Prefix and Object Suffix parameters as the existing trigger.
source None No The new trigger is configured with the same value for the Object Prefix parameter as the existing trigger. If you do not specify the Object Suffix parameter, objects with the zip suffix are included.
None zip No The new trigger is configured with the same value for the Object Suffix parameter as the existing trigger. If you do not specify the Object Prefix parameter, objects with the source prefix are included.
source1 zip1 Yes The new trigger is configured with different values for the Object Prefix and Object Suffix parameters from the existing trigger.
source zip1 Yes The new trigger is configured with a different value for the Object Suffix parameter from that of the existing trigger.
source1 zip Yes The new trigger is configured with a different value for the Object Prefix parameter from the existing trigger.
oss:ObjectCreated:PostObject source zip Yes The new trigger is configured with a different value for the Trigger Event parameter from the existing trigger.