Triggers are mechanisms that define when a function is executed in response to specific events or conditions. They act as a bridge between an event and the action of a function, enabling event-driven architectures and simplifying complex workflows.
What is a trigger?
A function can be invoked by using the Function Compute console, SDKs, or event sources. Triggers act as a way to automatically call a function when certain events occur. They are a fundamental building block of event-driven applications.
When a trigger is created for a function, it defines a specific set of conditions or criteria that, when met, will cause the function to be executed automatically.
If you want to invoke multiple functions with a single event, you can combine Function Compute with CloudFlow. Specifically, you can invoke a function that starts a CloudFlow process, during which multiple other functions are invoked.
Sample scenarios
Triggers automate function execution. The following examples illustrate common scenarios where triggers can be used. Once set up, the trigger will automatically execute the specified function when certain criteria are met, as well as at defined times or intervals, without any manual intervention.
OSS trigger
You have an application that uploads images to your Object Storage Service (OSS) bucket, along with a function that can download, process, and save these images back to the bucket or to another service. To avoid having to manually invoke the function each time a new image is uploaded, you can configure an OSS trigger to do this automatically.
Simple Log Service trigger
You have an application that uses Simple Log Service for log collection, along with a function that can query and analyze these logs. To avoid having to manually invoke the function each time a new log is collected, you can configure a Simple Log Service trigger to do this automatically.
Time trigger
You have an application that requires hourly data collection, along with a function that can collect and process the data. To avoid having to manually invoke the function every hour, you can configure a time trigger to do this automatically.
Trigger types
Function Compute supports the following types of triggers, classified according to their integration methods:
Two-way integrated triggers: This type of trigger can be configured in both Function Compute and the event sources.
One-way integrated triggers: This type of trigger can only be configured in the event sources.
Event triggers for Alibaba Cloud services: This type of trigger can only be configured in Function Compute, but it allows you to set triggering rules in EventBridge instead of configuring them directly in the event sources.
Based on how they invoke a function, triggers can also be classified into synchronous invocation triggers and asynchronous invocation triggers. The following items describe the differences between the invocation methods. For more information, see Synchronous invocations.
Synchronous invocation: The function returns a response only after it finishes processing the event. For example, function invocations initiated in the Function Compute console are all synchronous invocations.
Asynchronous invocation: Function Compute returns a response immediately upon receiving the event and places it into an internal queue for processing.
Two-way integrated triggers
Trigger name | Supported invocation method | Document link | |
Time trigger | Asynchronous | ||
OSS trigger | Asynchronous | ||
Simple Log Service trigger | Synchronous | ||
CDN trigger | Synchronous | ||
Tablestore trigger | Synchronous | ||
Self-managed Apache RocketMQ trigger | Synchronous and asynchronous | ||
Simple Message Queue (formerly MNS) topic trigger | Asynchronous | Overview of Simple Message Queue (formerly MNS) topic trigger | |
HTTP trigger | Synchronous and asynchronous | ||
EventBridge-based triggers | Simple Message Queue (formerly MNS) queue trigger | Synchronous and asynchronous | |
ApsaraMQ for RocketMQ trigger | Synchronous and asynchronous | ||
ApsaraMQ for RabbitMQ trigger | Synchronous and asynchronous | ||
ApsaraMQ for Kafka trigger | Synchronous and asynchronous | ||
ApsaraMQ for MQTT trigger | Synchronous and asynchronous | ||
Data Transmission Service (DTS) trigger | Synchronous and asynchronous | ||
One-way integrated triggers
For one-way integrated triggers, you must configure them in the event sources.
Trigger name | Supported invocation method | Document link |
API Gateway trigger | Synchronous and asynchronous | |
Application Load Balancer (ALB) trigger | Synchronous and asynchronous | |
DataHub one-way trigger | Synchronous and asynchronous | |
IoT Platform trigger | Asynchronous | |
DataWorks trigger | Synchronous and asynchronous | |
CloudFlow | Synchronous and asynchronous |
Event triggers for Alibaba Cloud services
Trigger name | Supported invocation method | Document link |
Event triggers for Alibaba Cloud services | Synchronous and asynchronous |