ALB trigger

更新时间:
复制 MD 格式

Function Compute supports using Application Load Balancer (ALB) as an event source by adding a Function Compute-type server group to an ALB instance, enabling ALB to forward requests to Function Compute and invoke functions.

Overview

ALB supports adding Function Compute as a backend service. When ALB receives a request, it forwards the request to Function Compute and triggers a function invocation. After the function finishes running, Function Compute returns the result as a response to the requester.

Note

ALB and Function Compute (FC) communicate securely over Alibaba Cloud’s internal network.

Key features

  • Serverless architecture support: Adding Function Compute as a backend service to ALB simplifies building serverless applications and reduces O&M costs.

  • Automatic elastic scaling: Function Compute automatically scales compute resources up or down based on traffic, ensuring sufficient capacity during peak times and conserving resources during low-traffic periods.

  • High availability and fault tolerance: ALB and Function Compute together provide high availability and disaster recovery capabilities to ensure stable application operation.

Scenarios

  • Microservices: Use ALB’s advanced routing capabilities to route requests to different microservice functions. Function Compute dynamically scales to handle high-concurrency requests, improving system elasticity and reliability.

  • Real-time data processing: Route data processing requests through ALB to the appropriate functions. Function Compute enables real-time data processing with just a few lines of code and simple configuration.

  • Event-driven processing: ALB receives event-triggered requests and forwards them to the relevant functions. Function Compute processes the events and stores results in a database or sends them to other services, enabling dynamic, event-driven workflows.

  • Image and video processing: ALB receives image or video upload requests and routes them to dedicated processing functions. Function Compute provides elastic compute resources that scale automatically with the workload, ensuring efficient task completion.

Limits

  • For regions where ALB supports adding Function Compute as a backend service, see Regions that support attaching Function Compute to ALB.

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

  • An ALB Function Compute–type server group supports only one function as a backend server.

  • If the Handler Type for Function Compute 2.0 is set to Process event requests, you must configure an HTTP trigger when associating the function with ALB.

Scenario example

An e-commerce company deployed ALB in an Alibaba Cloud region to handle large volumes of user requests. As its business grew and user traffic increased, the company needed a flexible, efficient way to manage tasks such as dynamic content generation, user behavior analysis, and personalized recommendations.

To meet this need, the company combined Alibaba Cloud’s Function Compute service with ALB. This integration enabled efficient handling of these tasks and significantly improved user experience.

Prerequisites

You have created an ALB instance.

Procedure

Step 1: Create a function

  1. Log on to the Function Compute console. In the left-side navigation pane, click Functions.

  2. In the top navigation bar, select a region. On the Functions page, click Create Function.

  3. On the Create Function page, select the Event Function type, choose a runtime, select the default sample code, keep all other parameters at their default values, and then click Create. This topic uses the built-in Node.js runtime as an example.

  4. On the function details page, go to the Code tab and click Test Function.

    After successful execution, view the function result in the Response section. In this example, the returned result is hello world.

Step 2: Create a Function Compute–type server group

  1. In the Application Load Balancer (ALB) console, in the navigation pane on the left, choose Server Groups. In the top menu bar, select the destination region and click Create Server Group.

  2. In the Create Server Group dialog box, set Server Group Type to Function Compute Type, then click Create.

    Important

    When ALB health checks are enabled, each health check probe counts as a Function Compute request and incurs charges.

    Enter a name in Server Group Name, such as fc3.0.

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

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

    This topic uses the Configuration Mode Select Resource. For Function Name, select the function you created. Set Version to LATEST. To use Configure by ARN, first obtain the function ARN.

Step 3: Configure a listener

  1. In the navigation pane on the left, choose ALB > Instances and click the instance ID.

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

  3. On the Configure Listener wizard page, configure the listener protocol and port, then click Next.

    This topic uses the HTTP protocol and port 80. Keep other HTTP listener parameters at their default values or modify them as needed.

  4. On the Server Group wizard page, in the Server Group drop-down list, choose Function Compute Type, select your target server group, then click Next.

  5. On the Configuration Review wizard page, confirm your settings and click Submit.

Step 4: Connectivity test

After completing the preceding operations, Function Compute and ALB have established a connection. You can open a command-line window and run the command curl <ALB instance domain name> to test the connectivity between ALB and Function Compute.

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

  • If you access ALB over a private network, ensure the VPC of your current network matches the VPC of the ALB instance.

  • If you have configured domain name resolution for the ALB instance domain name and bound a custom domain name, replace alb-n9p0q18eh2pbw****.{region_id}.alb.aliyuncsslb.com with your custom domain name.

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

If you receive the following output, ALB successfully forwards requests to Function Compute and invokes the function.

curl alb-n9p0q18elxxx.alb.aliyuncsslb.com
hello world

Additional information