edit-icon download-icon

Bind custom domains

Last Updated: Nov 27, 2018

By binding custom domains, you can allow users to access the functions that are deployed in Function Compute through the custom domains and to run functions with HTTP triggers. This approach helps you construct web services through Function Compute.

You can bind custom domains in Function Compute and map the paths to functions that are in different services. Then you can access the functions using the corresponding custom domains.

Use cases

For example, assuming that you have a website with a domain name of api.app.com. To achieve lower costs and higher scalability, you want to migrate the web services to Function Compute without affecting services to external users. To be more specific, you want to avoid changing the links associated with the external services. In this case, you can bind custom domains for your services.

Comparison

Process Without custom domain binding With custom domain binding
Deployment phase
  1. Write the application code and deploy the applications to your server.
  2. Obtain the ICP registration for the domain names.
  3. Resolve the domain names to the IP address of your server.
  4. Map the paths to the services through web frameworks
.
  1. Write functions for applications in Function Compute and set HTTP triggers.
  2. Obtain or transfer ICP registration for the domain names through Alibaba Cloud.
  3. Resolve the domain names to the address of the Function Compute service: accountID.region.fc.aliyuncs.com
  4. Bind the domain names in Function Compute and map the paths to the functions.
Access phase
  1. Accessapi.app.com/login.
  2. Resolve the domain names to the IP address of the server.
  3. api.app.com/login Access the services deployed in the user server.
  1. Accessapi.app.com/login
  2. Resolve the domain names to the address of Function Compute.
  3. api.app.com/login Access the functions deployed in Function Compute.

Prerequisite

Build a web server based on HTTP triggers in advance. For more information about building a web server, see Tutorial: HTTP triggers.

Bind the custom domains

  1. Obtain or transfer the ICP registration for the domain names through Alibaba Cloud. For more information about ICP registration, see ICP registration guide.

  2. Resolve the domain name to your endpoint. To be specific, resolve the CNAME records to the domain name that is pointed to the endpoint IP address. Set CNAME records before binding in Function Compute. For more information about DNS resolution, see DNS settings.

    For example, if your domain name is app.com, your account ID is 12345, and your Function Compute service is deployed in the China (Shanghai) region, then you must set the CNAME of app.com to be 12345.cn-shanghai.fc.aliyuncs.com.

  3. Bind the custom domain names in Function Compute, and map the paths to the functions.

    Note: Functions that are bound to the same domain name must be deployed in the same region but can belong to different services.

    For example, you can trigger the execution of function1 in service1 by the request path “/a” and trigger the execution of function2 in service2 by the request path “/b”.

    Only functions that have HTTP triggers configured can be triggered for execution through custom domain names.

Console operation

  1. Log on to the Go to the Function Compute console.

    custom-domain

  2. Click Custom Domain Management on the right of the home page to bind custom domain names and set routing rules. For more information, see the next section Routing rules.

    AddCName

Routing rules

You must map the paths to the functions for the custom domain names. Executions of different functions are triggered by different request paths. Function Compute supports exact matching and fuzzy matching. Specific rules are as follows:

Exact matching

For exact matching, the actual request path must be exactly the same as the request path that is set. For example, if path /a is set to trigger the execution of function f1 of service s1 (referred to as “s1/f1”) the path /a/ cannot trigger the execution of f1.

Fuzzy matching

It supports the wildcard character * included only at the end of the path. For example, /login/* represents all of the request paths. Specifically, the prefixes /login/ and /login/* are mapped to s2/f2. In this case, both /login/a and /login/b/c/d trigger the execution of f2.

  • Matching priority: exact match first and then fuzzy match
  • Matching algorithm: longest prefix match

Example

Assuming that the domain name is api.app.com, and the routing rules are as follows:

Path ServiceName FunctionName
/ s1 f1
/* s2 f2
/login s3 f3
/login/a s4 f4
/login/* s5 f5

The matching results are as follows:

RequestURI MatchedServiceName MatchedFunctionName MatchedPath
api.app.com s1 f1 /
api.app.com/user s2 f2 /*
api.app.com/login s3 f3 /login
api.app.com/login/a s4 f4 /login/a
api.app.com/login/a/b s5 f5 /login/*
api.app.com/login/b s5 f5 /login/*

Tutorials

For more information, see Binding custom domain names.

Contact Us if you have any further questions.

Thank you! We've received your feedback.