If any change is made to 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 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, the feature covers the following COS events:
||All upload events mentioned below can trigger the SCF function
||Creating a file via the Put Object API
||Creating a file via the Post Object API
||Creating a file via the Put Object - Copy API
||Creating a file with the CompleteMultipartUploadt API
||Triggers the function when image origin-pull occurs
||Triggers the function when an object is created through cross-region replication
||All deletion events mentioned below can trigger the SCF function
||Deleting an object via the Delete Object API or deleting an object with a specified version using `versionid` from a bucket for which versioning is not enabled
||Deleting an object via the Delete Object API from a bucket for which versioning is enabled or suspended
||Triggers the function when an ARCHIVE restoration job is created
||Triggers the function when an ARCHIVE restoration job is completed
How to Use COS Event Notification
Please follow the steps below:
- 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 Creat a Function. The way to write the function varies by programming language. For more information, see the SCF documentation.
- 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.
- 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.
- 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 in the console or using the COS Browser and then go to SCF Console > Function Details > Execution Logs to check if everything works properly.
For more information on SCF COS triggers, see COS Trigger.