All Products
Search
Document Center

Function Compute:ALB triggers

Last Updated:Dec 03, 2025

Function Compute allows you to use Application Load Balancer (ALB) as an event source, enabling you to configure ALB triggers for your functions. By specifying a function from Function Compute as a backend server of an ALB instance, you can forward requests from ALB to Function Compute to invoke your function.

Overview

You can add Function Compute as a backend service of ALB. This way, when ALB receives a request, it forwards the request to Function Compute. After Function Compute executes the corresponding function, the response is returned to the requester.

Note

ALB and Function Compute communicate over the secure internal network of Alibaba Cloud.

Key features

  • Serverless architecture: By adding Function Compute as a backend service of ALB, you can build serverless applications with ease. This significantly reduces O&M costs.

  • Auto scaling: Function Compute automatically scales up or down computing resources based on traffic. This ensures that your applications have sufficient computing power during peak hours while conserving resources during off-peak hours.

  • High availability and fault tolerance: ALB and Function Compute work together to provide high availability and disaster recovery capabilities. This ensures the stable operation of your applications.

Applicable scenarios

  • Microservices: By leveraging advanced routing capabilities, ALB forwards requests to various microservice functions. Meanwhile, Function Compute dynamically scales resources to handle the large number of concurrent requests, which enhances the elasticity and reliability of the system.

  • Real-time data processing: ALB forwards data processing requests to the appropriate functions, and the functions process data in real time with minimal code and simple configurations.

  • Event-driven scenarios: ALB forwards incoming events to the appropriate functions, and the functions process these events and either store the results in a specified database or send them to other services. This enables dynamic event processing.

  • Image and video processing: ALB forwards uploaded images and videos to the appropriate functions for processing, and Function Compute provides elastic computing resources that automatically scale based on the workload. This ensures efficient processing.

Limits

  • You are allowed to specify a function from Function Compute as a backend server of an ALB instance only in certain regions. For more information about these regions, see Regions in which you can add Function Compute as a backend service of ALB.

  • The ALB instance and the function must be in the same region.

  • You can add only one function from Function Compute to a server group of an ALB instance.

  • If you create a function in Function Compute 2.0 and set Handler Type to Event Handler, you must configure an HTTP trigger when specifying this function as a backend server of an ALB instance.

Sample scenario

An e-commerce enterprise deployed ALB in an Alibaba Cloud region to manage the high volume of user requests on its platform. As the business expands and the number of users continues to grow, the enterprise requires a flexible and efficient solution for tasks like dynamic content generation, user behavior analysis, and personalized recommendations.

To meet these demands, the enterprise integrates Function Compute with ALB. This combination efficiently handles those tasks and significantly enhances user experience.

image

Prerequisites

An ALB instance is created. For more information, see Create an ALB instance.

Procedure

Step 1: Create a function

  1. Log on to the Function Compute console, in the left-side navigation pane, choose Function Management > Functions. On the Functions page, select a region in the top navigation bar, and then click Create Function.

  2. On the Create Function page, choose Event Function, select a runtime and a default sample code, use the default values for other parameters, and then click Create.

    In this example, a built-in Node.js runtime is used.

  3. On the Code tab of the Function Details page, click Test Function.

    After the function is executed, the execution result hello world is returned.

Step 2: Create a server group of the Function Compute type

  1. Log on to the Server Load Balancer (SLB) console, in the left-side navigation pane, choose ALB > Server Groups. Select a region in the top navigation bar, and then click Create Server Group.

  2. In the Create Server Group dialog box, set Server Group Type to Function Compute, enter a server group name, and then click Create.

    Important

    If health check is enabled, health check probes will be treated as requests to Function Compute and will incur charges. For more information about billing, see Resource usage items.

    创建RS

  3. In the dialog box that says The server group is created, click Add Backend Server.

  4. In the Add Backend Server panel, select the function that you created and click OK.

    In this example, Configuration Method is set to Service, Function is set to a function that was created, and Version is set to LATEST. If you prefer to use the Alibaba Cloud Resource Name (ARN) configuration method, you must obtain the function ARN in advance. For more information about how to obtain it, see Obtain the ARN of a function.

    添加函数为后端服务器

Step 3: Configure a listener

  1. In the left-side navigation pane, choose ALB > Instances. On the page that appears, find the ALB instance that you want to manage and click its ID.

  2. Click the Listener tab, and then click Create Listener.

  3. In the Configure Listener step, configure the listener protocol and listener port, and then click Next.

    We recommend that you use HTTP and port 80. If you choose to create an HTTP listener, you can use the default values for other parameters or modify them as needed. For more information, see Add an HTTP listener.

    监听

  4. In the Select Server Group step, select Function Compute from the Server Group drop-down list, select the server group that you created in Step 2, and then click Next.

    选择服务器组

  5. In the Configuration Review step, confirm the configurations, and then click Submit.

Step 4: Test the connectivity

After you perform the preceding operations, a connection is established between Function Compute and ALB. You can open the CLI and run the curl <ALB instance domain name> command to test the connectivity between the ALB instance and Function Compute.

Note
  • Before you run the following command, replace alb-n9p0q18eh2pbw****.{region_id}.alb.aliyuncsslb.com with the actual domain name of your ALB instance.

  • If you access the ALB instance over an intranet, ensure that the Virtual Private Cloud (VPC) instance that includes the on-premises network is the same one where the ALB instance is deployed.

  • If you have configured domain name resolution (DNS) for the domain name of the ALB instance and bound a custom domain name, replace alb-n9p0q18eh2pbw****.{region_id}.alb.aliyuncsslb.com with your custom domain. For more information about how to configure DNS, see Step 4: Configure domain name resolution.

curl alb-n9p0q18eh2pbw****.{region_id}.alb.aliyuncsslb.com

The following result is returned, which indicates that the ALB instance can forward the request to Function Compute to invoke the function.

image

References

  • In real-world business scenarios, we recommend that you use a custom domain name and resolve it to the domain name of your ALB instance with a CNAME record. This allows the ALB instance to access your functions via the custom domain. For more information, see Step 4: Configure domain name resolution. Before you bind a custom domain name, ensure that you have registered the domain and completed the ICP filing process. For more information, see Register a domain name on Alibaba Cloud and ICP filing process.

  • If you enable health checks when you create the server group, health check probes will be treated as requests to Function Compute and will incur charges. For more information about server group creation, see Create a server group. For more information about billing, see Billable items and unit prices.