Triggers can cause functions to run. In an event-driven computing model, the event source is the event producer, and the function is the event handler. Triggers manage different event sources in a centralized manner. In the event source, when an event occurs, if the rules defined by the trigger are met, the event source will automatically call the function associated with the trigger.

What is a trigger?

Function Compute uses a computing model in which function invocation is driven by events. The execution of a function can be triggered by the Function Compute console or SDK, or by other event sources. You can create a trigger in a specified function that describes a set of rules. When an event meets these rules, the event source triggers the associated function.

Operation

  • Example 1: The image status change in the Object Storage Service (OSS) triggers function execution

    Assume that an application uses OSS to store uploaded graphics files. You can invoke functions to download and process these images, and then store the results in OSS or another service. If OSS can help us focus on newly uploaded images and automatically call the associated functions, you do not need to call the functions yourself, thus simplifying the development and use process. OSS event triggers can automatically detect these file upload events and invoke functions in Function Compute. After you configure an OSS event trigger, newly uploaded graphics files are automatically downloaded and processed.

  • Example 2: Log update triggers function execution in Log Service

    An application uses Log Service to regularly collect updated logs. You can directly call functions to query and analyze incremental logs. If SLS can help us pay attention to the updated logs and automatically call the associated functions, you do not need to call the functions yourself. SLS triggers can automatically detect these events and invoke functions in Function Compute. After you configure an SLS trigger, incremental data from newly updated logs is automatically consumed.

  • Example 3: Invoking functions at a specified time interval

    Assume that an application needs to collect data at one-hour intervals. You can invoke functions every hour to collect and process this data. Without event triggers, you would need to remember to manually invoke these functions every hour. Time triggers can automatically detect time events and invoke functions in Function Compute. After you configure a time trigger, data is automatically collected and processed every hour.

Trigger Type

According to the trigger integration mode, Function service supported triggers are divided into two-way integrated triggers, one-way integrated triggers, and EventBridge triggers. The differences between the three types of triggers are as follows:
  • Two-way integrated triggers: You can configure triggers on both Function service and event source.
  • One-way integrated triggers: Currently, only triggers can be configured in the event source.
  • EventBridge Trigger: You can configure triggers in the Function service and create function trigger rules in the EventBridge without configuring them in the event source.
From the perspective of function calling methods, triggers can be divided into synchronous calling triggers and asynchronous calling triggers. The differences between the two calling methods are as follows. For more information, see Overview.
  • Synchronous invocation: After an event is processed by a function, the result is directly returned. For example, invoking a function in the Function Compute console is a synchronous invocation.
  • Asynchronous invocation: After an event is added to the internal queue of Function Compute, the request ID is returned. Function Compute ensures that events in the queue are reliably processed later.

Two-way integrated trigger

The name of the trigger. Request method References
Time Trigger Asynchronous calls Overview
OSS event trigger Asynchronous calls Overview
Trigger for Log Service (SLS) Synchronous calls SLS trigger
CDN event triggers Synchronous calls Overview
Tablestore trigger Synchronous calls Overview
MNS topic trigger Asynchronous calls MNS topic trigger
HTTP trigger Synchronous calls Overview

One-way integration trigger

The name of the trigger. Request method Sample link
API Gateway Trigger Synchronous calls API Gateway trigger
Message Queue for Apache Kafka Connector Trigger Synchronous calls Create a Function Compute sink connector

EventBridge trigger

The name of the trigger. Request method Sample link
Message Queue for Apache RocketMQ trigger Synchronous calls RocketMQ Trigger
MSMQ RabbitMQ triggers Synchronous calls RabbitMQ Trigger
MNS queue trigger Synchronous calls MNS queue trigger
Alibaba Cloud official event source trigger Synchronous calls Official event source trigger