All Products
Search
Document Center

Function Compute:Trigger overview

Last Updated:Oct 23, 2024

A trigger is a method that is used to trigger function execution. 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 using SDKs or event sources. You can create triggers for a function. A 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 CloudFlow. For example, you can invoke a function by a trigger to start a CloudFlow process, in which multiple functions can be invoked. For more information, see the GitHub example.

Sample scenarios

  • Example 1: Trigger a 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 OSS or other services. If OSS can automatically detect newly uploaded images and invoke the associated functions, you do not have to manually invoke the functions. This helps simplify code development and resource usage. OSS event triggers can automatically detect the images and invoke functions in Function Compute. After the trigger is configured, the associated function is triggered to download and process images when new images are uploaded.

  • 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 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 such events and invoke functions in Function Compute. After you configure a Simple Log Service trigger, the associated functions are triggered when logs are updated to automatically consume incremental logs.

  • Scenario 3: Trigger function execution at specified intervals

    An application needs to collect data every other hour. You can invoke a function every other hour to collect and process data. If the function in the Function Compute can be automatically executed every other hour, you do not need to manually invoke the function. 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 functions are triggered to automatically collect and process data at specified time points.

Trigger types

Function Compute supports the following types of triggers based on how 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.

  • 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 invocation triggers and asynchronous invocation triggers based on how functions are invoked. The following items describe the differences between the 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 initiated 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 processed in a reliable manner.

Two-way integrated triggers

Trigger name

Invocation method

References

Time trigger

Asynchronous invocation

Overview

OSS trigger

Asynchronous invocation

Overview of OSS event triggers

Simple Log Service trigger

Synchronous invocation

Overview

CDN trigger

Synchronous invocation

Overview

Tablestore trigger

Synchronous invocation

Overview

Self-managed Apache RocketMQ trigger

Synchronous or asynchronous invocation

Create an Apache RocketMQ trigger

Simple Message Queue (formerly MNS) topic trigger

Asynchronous invocation

Overview

HTTP trigger

Synchronous or asynchronous invocation

Overview

EventBridge-based triggers

Simple Message Queue (formerly MNS) queue trigger

Synchronous or asynchronous invocation

Simple Message Queue (formerly MNS) queue triggers

ApsaraMQ for RocketMQ trigger

Synchronous or asynchronous invocation

ApsaraMQ for RocketMQ triggers

ApsaraMQ for RabbitMQ trigger

Synchronous or asynchronous invocation

RabbitMQ triggers

ApsaraMQ for Kafka trigger

Synchronous or asynchronous invocation

ApsaraMQ for Kafka triggers

ApsaraMQ for MQTT trigger

Synchronous or asynchronous invocation

ApsaraMQ for MQTT triggers

Data Transmission Service (DTS) trigger

Synchronous or asynchronous invocation

DTS triggers

One-way integrated triggers

Note

For one-way integrated triggers, you must configure the triggers in event sources.

Trigger name

Invocation method

Reference

API Gateway trigger

Synchronous or asynchronous invocation

API Gateway trigger overview

Application Load Balancer (ALB) trigger

Synchronous or asynchronous invocation

ALB triggers

DataHub one-way trigger

Synchronous or asynchronous invocation

DataHub one-way trigger

IoT Platform trigger

Asynchronous

IoT Platform

DataWorks trigger

Synchronous or asynchronous invocation

DataWorks

CloudFlow

Synchronous or asynchronous invocation

CloudFlow

Event triggers for Alibaba Cloud services

Trigger name

Invocation method

Reference

Alibaba Cloud event source trigger

Synchronous or asynchronous invocation

Configure event triggers for Alibaba Cloud services