A trigger is a way to trigger functions. In an event-driven computing model, an event source is an event producer, and a function is an event processor. Triggers are used to manage different event sources in a centralized manner. When an event that matches the rules 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 SDKs and other 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 CloudFlow. You can specify that a function starts a CloudFlow process when a function is triggered. Multiple functions can be invoked in the process. For more information, see the demo.
Sample scenarios
Scenario 1: Trigger function execution when the status of images stored in OSS changes
An application stores images in Object Storage Service (OSS). You can invoke a function to download and process the images. The function stores the processed images in OSS or another service. If OSS can automatically detect newly uploaded images and invoke the associated function, you do not have to manually invoke the function. This helps simplify the development and use processes. In this case, you can configure an OSS trigger to detect newly uploaded images and invoke the function in Function Compute. After the trigger is configured, the associated function is triggered to download and process images when new images are uploaded.
Scenario 2: Trigger function when logs in Simple Log Service are updated
An application uses Simple Log Service to collect updated logs at regular intervals. You can invoke a function to query and analyze incremental logs. If Simple Log Service can automatically detect updated logs and invoke the associated function, you do not need to manually invoke the function. In this case, you can configure a Simple Log Service trigger to detect updated logs and invoke the function in Function Compute. After the trigger is configured, the associated function is triggered to consume increment logs when logs are updated.
Scenario 3: Trigger function execution at specified time
For example, an application needs to collect data every 1 hour. You can invoke a function every one hour to collect and process the data. If the functions in Function Compute can be automatically executed every hour, you no longer need to manually invoke the functions. In this case, you can configure a time trigger to detect time events and invoke the function in Function Compute. After you configure a time trigger, the associated function is triggered to automatically collect and process data at specified intervals.
Trigger types
Triggers of Function Compute are categorized into the following two types based on the trigger integration methods:
Two-way integrated triggers: Triggers that can be configured in Function Compute and event sources.
Event triggers for Alibaba Cloud services: 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 how functions are invoked. The following items describe the differences between the invocation methods. For more information, see Synchronous invocation.
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 the events are written to the internal queues of Function Compute. Function Compute ensures that the messages are processed in a reliable manner.
Two-way integrated triggers
Trigger name | Invocation method | References | |
Time triggers | Asynchronous invocation | ||
OSS triggers | Asynchronous invocation | ||
Simple Log Service triggers | Synchronous invocation | ||
Alibaba Cloud CDN triggers | Synchronous invocation | ||
Tablestore triggers | Synchronous invocation | ||
Simple Message Queue (formerly MNS) topic triggers | Asynchronous invocation | ||
Self-managed Apache RocketMQ triggers | Synchronous and asynchronous invocations | ||
HTTP triggers | Synchronous and asynchronous invocations | ||
EventBridge-based triggers | Simple Message Queue (formerly MNS) queue triggers | Synchronous and asynchronous invocations | Overview of Simple Message Queue (formerly MNS) queue triggers |
ApsaraMQ for RocketMQ triggers | Synchronous and asynchronous invocations | ||
ApsaraMQ for RabbitMQ triggers | Synchronous and asynchronous invocations | ||
ApsaraMQ for Kafka triggers | Synchronous and asynchronous invocations | ||
ApsaraMQ for MQTT triggers | Synchronous and asynchronous invocations | ||
Data Transmission Service (DTS) triggers | Synchronous and asynchronous invocations |
Event triggers for Alibaba Cloud services
Trigger name | Invocation method | References |
Event triggers for Alibaba Cloud services | Synchronous and asynchronous invocations |