A trigger is a way to trigger function execution. In an event-driven computing model, an event source is an event producer, and a function is an event handler. Triggers manage different event sources in a centralized manner. When an event that matches the rules that are defined for a trigger occurs, the event source invokes the function that is associated with the trigger.
What is a trigger?
Function Compute provides a computing model in which function execution is driven by events. The execution of a function can be triggered by using the Function Compute console, SDKs, or event sources. You can create a trigger in a specified function. The trigger contains a set of rules. When an event that meets the rules occurs, the event source triggers the associated function.
If you want to use a trigger to trigger multiple functions, you can use Function Compute along with Serverless workflow, in which you first use a trigger to trigger a function and then the function starts a Serverless workflow flow to invoke multiple functions. For more information, see Example.
Scenarios
- Example 1: Trigger function execution when the status of images stored in Object Storage Service (OSS) changes
In this example, an application uses Object Storage Service (OSS) to store uploaded images. You can invoke functions to download and process these images, and then store the processed images in Object Storage Service (OSS) or another service. If you use an OSS event trigger, you do not need to invoke the functions when new images are uploaded to Object Storage Service (OSS). OSS event triggers can automatically detect the images and invoke functions in Function Compute. After you configure an OSS event trigger, functions are triggered when images are uploaded. The functions automatically download and process the images
- Example 2: Trigger function execution when logs in Log Service are updated
In this example, an application uses Log Service to collect updated logs at scheduled times. You can invoke functions to query and analyze the incremental logs for the application. If you use a Log Service event trigger, you do not need to invoke the functions after logs are updated. Log Service triggers can automatically detect these events and invoke functions in Function Compute. After you configure a Log Service trigger, functions are triggered when logs are updated. The functions automatically consume the incremental logs.
- Example 3: Trigger function execution at a specified time
For example, an application needs to collect data at one-hour intervals. You can invoke functions every one hour to collect and process the data. If you use a time event trigger, you do not need to invoke the functions in Function Compute every hour. Time triggers can automatically detect time events and invoke functions in Function Compute. After you configure a time trigger, the functions are triggered to automatically collected and processed data at a specified time.
Trigger types
- Two-way integrated triggers: You can configure triggers in Function Compute and event sources.
- One-way integrated triggers: You can only configure triggers in event sources.
- EventBridge triggers: You can configure triggers in Function Compute and create function trigger rules in EventBridge. You do not need to configure triggers in event sources.
- Synchronous invocation: Results are returned after events are processed by a function. For example, a function invocation in the Function Compute console is a synchronous invocation.
- Asynchronous invocation: Results are returned after events are written to the internal queues of Function Compute. Function Compute ensures that events in the queue are processed as expected.
Two-way integrated triggers
Trigger name | Invocation method | References |
---|---|---|
Time trigger | Asynchronous invocation | Overview |
OSS trigger | Asynchronous invocation | Overview of OSS event triggers |
Log Service trigger | Synchronous invocation | Log Service triggers |
CDN event trigger | Synchronous invocation | Overview |
Tablestore trigger | Synchronous invocation | Overview |
Message Service (MNS) topic trigger | Asynchronous invocation | MNS topic trigger |
HTTP trigger | Synchronous invocation | Overview |
One-way integrated triggers
Trigger name | Invocation method | References |
---|---|---|
API Gateway trigger | Synchronous invocation | API Gateway trigger |
Message Queue for Apache Kafka Connector trigger | Synchronous invocation | Create a Function Compute sink connector |
EventBridge triggers
Trigger name | Invocation method | References |
---|---|---|
Message Queue for Apache RocketMQ trigger | Synchronous invocation | Message Queue for Apache RocketMQ triggers |
Message Queue for RabbitMQ trigger | Synchronous invocation | RabbitMQ triggers |
MNS queue trigger | Synchronous invocation | MNS queue triggers |
Alibaba Cloud event source trigger | Synchronous invocation | Event triggers for Alibaba Cloud services |