All Products
Search
Document Center

Function Compute:Trigger overview

Last Updated:Feb 02, 2024

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 by the Function Compute console, SDKs, or 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.

Note

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 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 the images for processing and store the processed images in 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 directly invoke 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 Simple 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.

  • 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 invocation.

  • 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 invocations

Configure a time trigger

OSS trigger

Asynchronous invocations

Overview

Simple Log Service trigger

Synchronous invocations

Configure a Simple Log Service trigger

CDN trigger

Synchronous invocations

Overview

Tablestore trigger

Synchronous invocations

Configure a Tablestore trigger

MNS topic trigger

Asynchronous invocations

Configure an MNS topic trigger

MNS queue trigger

Synchronous or asynchronous invocations

MNS queue triggers

ApsaraMQ for RocketMQ trigger

Synchronous or asynchronous invocations

ApsaraMQ for RocketMQ triggers

ApsaraMQ for RabbitMQ trigger

Synchronous or asynchronous invocations

ApsaraMQ for RabbitMQ trigger

ApsaraMQ for Kafka trigger

Synchronous or asynchronous invocations

ApsaraMQ for Kafka triggers

Self-built Apache RocketMQ trigger

Synchronous or asynchronous invocations

Create an Apache RocketMQ trigger

ApsaraMQ for MQTT trigger

Synchronous or asynchronous invocations

ApsaraMQ for MQTT triggers

Data Transmission Service (DTS) trigger

Synchronous or asynchronous invocations

DTS triggers

HTTP trigger

Synchronous or asynchronous invocations

Overview

Event triggers for Alibaba Cloud services

Trigger name

Invocation method

Reference

Event triggers for Alibaba Cloud services

Synchronous or asynchronous invocations

Configure event triggers for Alibaba Cloud services