A trigger is a way to trigger function. In an event-driven computing model, an event source is an event producer, and a function is an event processer. 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 in the Function Compute console, or by using SDKs and event sources. You can create a trigger in a 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 need to use a trigger to trigger multiple functions, you can use Function Compute together with Serverless Workflow. When a function is triggered by a trigger, the Serverless Workflow process is started. You can invoke multiple functions in the process. For more information, see Example.
Example scenarios
Example 1: Trigger function when the status of images stored in Object Storage Service (OSS) changes
An application stores images in OSS. You can invoke a function to download the images for processing and store the processed images in the OSS or other services. If OSS can automatically detect newly uploaded image and invoke the associated functions, you do not have to manually invoke the functions. This helps simplify the development and use processes. 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 Simple Log Service are updated
An application uses Simple Log Service to collect updated logs at regular intervals. You can call functions to query and analyze incremental logs. If Simple Log Service can automatically detect updated logs and invoke the associated functions, you do not need to manually invoke the functions. Simple 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 the functions in the Function Compute can be automatically executed every hour, you no longer need to manually invoke the functions. 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 collect and process data at a specified time.
Trigger types
Function Compute supports the following types of triggers based on the way triggers are integrated:
Two-way integrated triggers: Triggers that can be configured in Function Compute and event sources.
One-way integrated triggers: Triggers that can be configured only in event sources.
Alibaba Cloud service event triggers: Triggers that can be configured in Function Compute and EventBridge. You do not need to configure the triggers in event sources.
Triggers can be classified into synchronous triggers and asynchronous triggers based on the methods that functions are invoked. The following items describe the differences between the two invocation methods. For more information, see Synchronous invocations.
Synchronous invocations: 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 invocations: Results are returned after the events are written to the internal queues of Function Compute. Function Compute ensures that the messages are reliably processed.
Two-way integrated triggers
Trigger name | Invocation method | Reference |
Time trigger | Asynchronous invocation | |
OSS trigger | Asynchronous invocation | |
Simple Log Service trigger | Synchronous invocation | |
CDN trigger | Synchronous invocation | |
Tablestore trigger | Synchronous invocation | |
MNS topic trigger | Asynchronous invocation | |
MNS queue trigger | Synchronous or asynchronous invocation | |
ApsaraMQ for RocketMQ trigger | Synchronous or asynchronous invocation | |
ApsaraMQ for RabbitMQ trigger | Synchronous or asynchronous invocation | |
ApsaraMQ for Kafka trigger | Synchronous or asynchronous invocation | |
Self-built Apache RocketMQ trigger | Synchronous or asynchronous invocation | |
ApsaraMQ for MQTT trigger | Synchronous or asynchronous invocation | |
Data Transmission Service (DTS) trigger | Synchronous or asynchronous invocation | |
HTTP trigger | Synchronous or asynchronous invocation |
One-way integrated triggers
For one-way integrated triggers, you must configure the triggers in the event sources.
Trigger name | Invocation method | Reference |
API Gateway trigger | Synchronous or asynchronous invocation | |
ALB trigger | Synchronous or asynchronous invocation | |
DataHub one-way trigger | Synchronous or asynchronous invocation | |
IoT Platform | Asynchronous invocation | |
DataWorks | Synchronous or asynchronous invocation | |
Serverless Workflow (SWF) | Synchronous or asynchronous invocation |
Event triggers for Alibaba Cloud services
Trigger name | Invocation method | Reference |
Event triggers for Alibaba Cloud services | Synchronous or asynchronous invocation |