All Products
Search
Document Center

Function Compute:Trigger overview

Last Updated:Sep 19, 2024

A trigger is a method that is used to trigger function execution. In an event-driven computing model, event sources produce events, functions process events, and triggers manage 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 or event sources. You can create a trigger in a specified 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 CloudFlow. When a function is triggered by a trigger, a CloudFlow process is started. You can invoke multiple functions in the process. For more information, see the 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 images and invoke the associated functions, you do not have to manually invoke the functions. This helps simplify code development and resource use. 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 such 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 incremental logs.

  • Scenario 3: Trigger function execution at specified intervals

    An application needs to collect data at one-hour intervals. You can invoke a function every one hour to collect and process data. If the function in the Function Compute can be automatically executed every 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 an associated 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

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 are also categorized into synchronous triggers and asynchronous triggers based on the method in which functions are invoked. The following items describe the differences between the two invocation methods. For more information, see Synchronous invocations.

  • 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 invocations: Results are returned after 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

Overview

OSS trigger

Asynchronous

Overview of OSS event triggers

Simple Log Service trigger

Synchronous

Simple Log Service triggers

CDN trigger

Synchronous

Overview

Tablestore trigger

Synchronous

Overview

Self-managed Apache RocketMQ trigger

Synchronous and asynchronous

Create an Apache RocketMQ trigger

Simple Message Queue (formerly MNS) topic trigger

Asynchronous

Overview

HTTP trigger

Synchronous and asynchronous

Overview

Triggers based on EventBridge

Simple Message Queue (formerly MNS) queue trigger

Synchronous and asynchronous

Simple Message Queue (formerly MNS) queue triggers

ApsaraMQ for RocketMQ trigger

Synchronous and asynchronous

ApsaraMQ for RocketMQ triggers

ApsaraMQ for RabbitMQ trigger

Synchronous and asynchronous

RabbitMQ triggers

ApsaraMQ for Kafka trigger

Synchronous and asynchronous

ApsaraMQ for Kafka triggers

ApsaraMQ for MQTT trigger

Synchronous and asynchronous

ApsaraMQ for MQTT triggers

DTS trigger

Synchronous and asynchronous

DTS triggers

One-way integrated triggers

Note

One-way integrated triggers must be configured in event sources.

Trigger name

Invocation method

Reference

API Gateway trigger

Synchronous and asynchronous

API Gateway trigger overview

ALB trigger

Synchronous and asynchronous

ALB triggers

DataHub one-way trigger

Synchronous and asynchronous

DataHub one-way trigger

IoT Platform trigger

Asynchronous

IoT Platform

DataWorks trigger

Synchronous and asynchronous

DataWorks

CloudFlow trigger

Synchronous and asynchronous

CloudFlow

Event triggers for Alibaba Cloud services

Trigger name

Invocation method

Reference

Event triggers for Alibaba Cloud services

Synchronous and asynchronous

Configure event triggers for Alibaba Cloud services