Overview
If any change is made to Cloud Object Storage (COS) resources (such as new files uploaded or files deleted), you will receive prompt notification. Event notification can be used together with Serverless Cloud Function (SCF) to meet the needs of more application scenarios: Interaction with other Tencent Cloud services: For example, purge CDN cache or update the database when a new file is uploaded to COS.
System integration: Your own service APIs can be called when files in COS are created, deleted, or overwritten. In user-generated content (UGC) scenarios, with the event notification feature, the client side will be able to interact with the server side.
Data processing: Files in COS can be automatically processed, such as automatic decompression and AI recognition.
COS event notification has the following features:
Async processing: sending notifications does not affect normal COS operations.
Notification targets: notifications can only be sent to SCF functions in the same region.
Currently, an SCF function can be triggered by the following COS events:
|
cos: ObjectCreated:* | All upload events mentioned below |
cos: ObjectCreated:Put | An object is created using the Put Object API |
cos: ObjectCreated:Post | An object is created using the Post Object API |
cos: ObjectCreated:Copy | An object is created using the Put Object - Copy API |
cos: ObjectCreated:CompleteMultipartUpload | An object is created using the Complete Multipart Upload API |
cos:ObjectCreated:Origin | Image origin-pull occurs |
cos:ObjectCreated:Replication | An object is created using cross-region replication |
cos: ObjectRemove:* | All deletion events mentioned below |
cos: ObjectRemove:Delete | An object is deleted from an unversioned bucket using the Delete Object API, or an object with a specified version is deleted by specifying versionid |
cos: ObjectRemove:DeleteMarkerCreated | An object is deleted from a versioning-enabled or versioning-suspended bucket using the Delete Object API |
cos:ObjectRestore:Post | An ARCHIVE restoration job is created |
cos:ObjectRestore:Completed | An ARCHIVE restoration job is completed |
How to Use COS Event Notification
Please follow the steps below:
1. Create an SCF function
You can create a function in the SCF console or using the CLI. When creating the function, you need to select the runtime environment based on the language you will use to write the function and submit the function code either by editing online or uploading a local code package. You can also use a preconfigured SCF template to simplify the creation. For more information, see Create a Function. The way to write the function varies by programming language. For more information, see the SCF documentation. 2. Test the function
Once a function is created, you can test it with a test template which can simulate COS events and trigger the function. For more information, see Testing a Function. 3. Add a trigger
After you finish the testing, you can bind the SCF function with a bucket by creating a COS trigger in the console or using the command line. For more information, see Creating a Trigger. 4. Check if the function works
After completing the steps above, you can make changes to the bucket in COS to see if everything works. For example, you can upload or delete files via the console or COSBrowser. Then, go to the SCF console, choose Function Service, click the name of the target function, and click Log Query to check if everything works properly. For more information on SCF COS triggers, see COS Trigger.
Was this page helpful?