After you host an application to Serverless App Engine (SAE), you can create a route for the application to distribute requests to other services or applications. This topic describes how to create and manage a route for an application based on an Application Load Balancer (ALB) instance.
Before you start
SLB
SAE
SAEVPCCreate an SAE namespace, and make sure that the ALB instance and the namespace reside in the same region and are associated with the same Virtual Private Cloud (VPC).
and make sure that the application for which you want to create a route and the application that receives requests at the backend belong to the same namespace.
Background information
Server Load Balancer (SLB) is a service that forwards network traffic across groups of backend servers to increase the throughput of your applications. It helps prevent service disruptions caused by single points of failure (SPOFs), improving the availability of applications. ALB is a member of the SLB family and is intended for protocols such as HTTP, HTTPS, and Quick UDP Internet Connections (QUIC) at the application layer. ALB is highly elastic and can process large volumes of traffic at the application layer. ALB supports complex routing and is integrated with other cloud-native services. ALB is designed as a cloud-native Ingress gateway solution recommended by Alibaba Cloud. For more information, see What is SLB?
Use cases
Forwarding traffic through different paths to a domain name used by one or more applications.
Forwarding traffic to different domain names that are resolved to the same IP address and used by one or more applications.
After you configure a route, you can access specific backend services or applications by using a URL in the <Domain name>:<Port number/Path> format.
Create a route
On the SAE Gateway Routing page, select a region and a namespace from the top navigation bar, and then click Create Gateway Route.
On the Create Route page that appears, configure the parameters as described in the following table and click Save.
Parameter
Description
Route Name
The name of the route that you want to create.
Network Type
The network type of the gateway that you want to use to forward requests.
Internet: You need to pay for the amount of traffic that is forwarded by an Internet gateway.
Private Network: You do not need to pay for the traffic that is forwarded by a private gateway because traffic is forwarded only within the VPC of the gateway.
Gateway Type
Select ALB.
ALB Instance
Select an ALB instance from the ALB Instance drop-down list. You can also click Create ALB Instance to create one. For more information, see Create and manage an ALB instance. In addition, SAE supports purchasing ALB instances on your behalf. The following purchase options are available:
Create a standard edition ALB instance (pay-as-you-go)
Create a WAF-enhanced ALB instance (pay-as-you-go)
If you choose to create an instance, the system automatically creates a pay-as-you-go instance of the specified network type. For billing details, see ALB billing overview.
NoteIf you don't see an ALB instance in the region, it may be because the ALB is in a different VPC than the one bound to the current namespace. In this case, go to the ALB console and create an instance in the same region and VPC as the namespace.
Frontend Protocol Type
The protocol that is used to forward requests.
HTTP: suitable for applications that need to identify data from different sources, such as mobile applications and games.
HTTPS: suitable for applications that require encrypted data transmission.
Access Port
The custom port number. Valid values: 0 to 65535.
Advanced Settings
Expand this section to set the following parameters:
Connection Request Timeout: Set the timeout period for requests to backend servers. Valid values: 1 to 180. Unit: seconds. If a backend server does not respond within the specified period, an HTTP 504 error code is returned.
Idle Connection Timeout Period: Set the duration of a connection when no requests are made. Valid values: 1 to 60. Unit: seconds. If no new requests are received within the specified timeout period, ALB temporarily closes the current connection. A new connection is established when the next request arrives.
Add HTTP Header Fields: Select one of the following HTTP header fields to obtain specific information.
Add X-Forwarded-For to retrieve client IP address: In the format of
X-Forwarded-For: <client-ip-address>, <proxy1>, <proxy2>, ….X-Forwarded-Foris enabled for ALB listeners by default.For more information about how to enable ALB to preserve client IP addresses, see Obtain client originating IP addresses on backend servers through an ALB.
Add CLB-ID to retrieve CLB instance IDs: In the format of
SLB-ID.Add X-Forwarded-Proto to retrieve the listener protocol of the CLB instance: In the format of
X-Forwarded-Proto: <originatingProtocol>.Add X-Forwarded-Port to retrieve the listener port of the CLB instance: In the format of
X-Forwarded-Port: <port>.Add X-Forwarded-Client-srcport to retrieve the port used by a client to connect to the CLB instance: In the format of
X-Forwarded-Client-srcport: <port>.
Data compression: When enabled, ALB compresses eligible responses with Gzip or Brotli to reduce bandwidth usage.
Compression conditions: A response is compressed if its
Content-Lengthheader exceeds 1024 bytes and the client'sAccept-Encodingrequest header includes a supported compression algorithm.Algorithm priority: If a client supports both Brotli and Gzip compression algorithms, ALB prioritizes the more efficient Brotli algorithm.
Supported
Content-Type:Brotli supports the compression of all content types.
Gzip supports the following types:
text/xml,text/plain,text/css,application/javascript,application/x-javascript,application/rss+xml,application/atom+xml,application/xml, andapplication/json.
Custom Forwarding Policy
Configure a forwarding rule as needed to forward frontend requests to a backend service. The following parameters are required:
Domain Name: The domain name to which you want to forward requests. If you leave this parameter empty, the rule applies to all domain names. You must configure domain name resolution in advance to access the application using the domain name. For more information, see Configure a CNAME record for an ALB instance.
Access Port: The access port you set earlier is used by default, and you cannot change it here.
Path: The access path. You cannot leave this parameter empty.
Backend Application: The application that receives requests. It must be in the same namespace as the application that forwards the requests.
Container Port: The port of the container that is used to access the backend application.
Rewrite Policy: When a frontend request is forwarded to a backend application, you can rewrite the path in the original request. For example, if you want to rewrite the frontend request path /AAA/a and /AAA/b to the backend application as /a and /b, set Path to /AAA/(.*) and set path to /${1} in the Rewrite Policy section.
NoteThe ports of listeners within an ALB instance must be unique.
You can also click + Add Rule to add custom forwarding rules under the same domain name.
You can also click + Add Domain Name to add custom forwarding rules for other domain names.
Default Forwarding Rule
ALB Instance: The ALB instance you selected earlier is used by default, and you cannot change it here.
Access Port: The access port you set earlier is used by default, and you cannot change it here.
Backend Application: The application that receives requests. It must be in the same namespace as the application that forwards the requests.
Container Port: The port of the container that is used to access the backend application.
NoteWe recommend that you configure the default forwarding policy for all requests that do not match the custom forwarding policy. If you do not configure the default forwarding policy, an access error is reported.
Verify the results
Method 1: Log on to the SLB console. On the ALB Instances page, check whether the listener is configured.
Method 2: Use a URL in the
<Domain name>:<Port number/Path>format to access the related service or application and check whether requests are forwarded based on the configured forwarding policy.
Manage a route
After a route is created, you can view the forwarding policies and events of the route, modify the route, or delete the route on the Gateway Routing page.