Function Compute can assign the subdomain fcapp.run
to each new HTTP trigger. You can use the domain name to access your RESTful applications. This topic describes how to use fcapp.run
to access your RESTful applications without modifying code.
Background information
Function Compute supports HTTP triggers, which allows functions to be invoked by HTTP requests. Function Compute uses a shared API Server to respond to the function invocations that are triggered by HTTP triggers. The path in the URL is used to route traffic to the function container. The HTTP request paths that the container receives contain route identifiers of Function Compute. A 404 error is reported if you have deployed a RESTful application in Function Compute.

Initially, Function Compute provided a native RESTful architecture in which each function worked as an independent resource. In this case, each function worked as an API operation to implement specified tasks. If a function corresponds to only one API operation, you do not need to use a set of routing logic in the function code to respond to requests from different URL paths.

Function Compute has introduced the custom runtime and custom container environments for functions. You can run your existing applications in Function Compute. You do not need to split your applications based on the recommended architectures in Function Compute. Developers tend to develop a large number of RESTful API operations in programs. The in-process routing logic is used to forward requests from different paths so that the requests are processed by using different methods.

Use fcapp.run to invoke a function
To resolve the preceding issues, Function Compute assigns a unique domain name to each new HTTP trigger in the {random-string}.{region_id}.fcapp.run
format. The following figure shows an example. When you use the domain name to access Function Compute, Function Compute routes traffic based on the domain name and forwards the traffic to the function container. This way, the routing does not rely on paths, and the customer code is not affected.
For example, if the /function1
, /function2
, and /function3
APIs are encapsulated in the function corresponding to the HTTP trigger, the following URLs are called by fcapp.run:
{random_string}.{region_id}.fcapp.run/function1
{random_string}.{region_id}.fcapp.run/function2
{random_string}.{region_id}.fcapp.run/function3

Use fcapp-test.run to perform debugging on an on-premises web page
The root domain for Function Compute is aliyuncs.com
, which cannot be used to provide website services. All function request results are downloaded as attachments in browsers. For webpage functions, the returned HTML text and JavaScript code cannot be displayed as expected. In this case, you can resolve this issue by binding a custom domain name that has obtained the ICP filling for the function. For more information, see Overview.
You can also resolve the preceding issues by using the test domain fcapp-test.run
and adding a domain resolution entry to the hosts file. Then, request results are no longer downloaded as attachments and you can perform debugging on webpages as expected. The following sample code provides an example of the script:
# 1. Obtain the domain name of fcapp.run from the page.
FC_DOMAIN='serviceName-functionName-vtnazzbxrr.cn-hangzhou.fcapp.run'
FC_TEST_DOMAIN=`echo ${FC_DOMAIN} | sed 's/fcapp.run/fcapp-test.run/g'`
echo "Function Compute domain name: ${FC_DOMAIN}"
echo "Function Compute test domain name: ${FC_TEST_DOMAIN}"
# 2. Query the IP address that is obtained after the domain name resolution.
FC_IP=`ping ${FC_DOMAIN} -c 1 | HEAD -1 | awk '{print $3}' | sed 's/[():]//g'`
echo "FC IP: ${FC_IP}"
# 3. Modify the hosts file to resolve the test domain name to the IP address for fcapp.run.
# If you do not have permissions, you need to manually add the content.
sudo -- sh -c "printf '\n${FC_IP} ${FC_TEST_DOMAIN}\n' >> /etc/hosts"
cat /etc/hosts
# 4. Use the test domain name to access the function in the browser.
curl -v "${FC_TEST_DOMAIN}"
Use Function Compute to run WordPress images
Function Compute allows you to migrate your RESTful applications without modifying the code. In this section, a WordPress application is migrated.
Before you start
Function Compute
ApsaraDB RDS
NoteYou can also use an existing ApsaraDB RDS for MySQL instance and initialize the account and database for the WordPress service.
Make sure that the virtual private cloud (VPC) configurations of Function Compute are the same as the VPC configurations of the ApsaraDB RDS for MySQL instance and that a whitelist is correctly configured.
Container Registry
Transfer WordPress images to Alibaba Cloud Container Registry. For more information, see Push and pull an image.
NoteYou can push and pull images by using an instance of Container Registry Personal Edition or Enterprise Edition. In this section, a Container Registry Personal Edition instance is used as an example.
Procedure
- Log on to the Function Compute console. In the left-side navigation pane, click Services & Functions.
- In the top navigation bar, select a region. On the Services page, click the desired service.
On the Functions page, click Create Function and select Use Container Image. Configure the parameters and click Create.
Select a WordPress image and set Listening Port to 80. For more information, see Create a custom container function.
Modify configurations of the function and inject the database configurations into the function container in the form of environment variables.
For more information about how to configure environment variables, see Environment variables.
Enter the domain name that is assigned by Function Compute to the HTTP trigger in the address bar of the browser to test the function.
After the function is created, Function Compute automatically creates an HTTP trigger. You can obtain the domain name from the configurations of the trigger. The API corresponding to the WordPress application is called by using the domain name as the root path.
NoteWebsite services can only be provided by using domain names for which ICP filing is obtained. You can configure a custom domain name, bind the domain name to your function, and then use the domain name to provide services. For more information, see Configure a custom domain name.