All Products
Search
Document Center

HTTPDNS:Create a function in Function Compute

Last Updated:Apr 17, 2025

This topic describes how to create a custom function in the Function Compute console, debug the function, and publish the service version that contains the function settings.

HTTPDNS supports both FC 2.0 and FC 3.0 function configurations. This topic describes how to create a function in the Function Compute console.

Create a 3.0 function

  1. Log on to the Function Compute console. In the top menu bar, select a Region.

  2. In the left navigation pane, select Functions. On the Functions page, click Create Function.image

  3. On the Create Function page, select "Event Function" and configure the parameters as needed. You can select the "HTTPDNS Custom Resolution" template for the code example. After you configure the parameters, click Create to enter the function editor.image

  4. After the editor is initialized, enter the function code. For more information about how to configure the function code, see Write a custom resolution function. If you selected the "HTTPDNS Custom Resolution" template, you can skip this step.

  5. Next, test your function. For more information about how to configure the input parameters of the function, see Write a custom resolution function. Click Test Function to confirm that the function can be executed correctly and the returned data meets your expectations.image

  6. After the test is complete, click Deploy Code to confirm that the code is deployed.

  7. Click Version Management, enter the prompt content, and create a version.image

At this point, the sample configuration in the FC 3.0 console is complete. You can go to the HTTPDNS console to add a function compute policy to configure the corresponding function.

Create a 2.0 function

We recommend that you use Function Compute 3.0. Function Compute 2.0 is no longer recommended. For more information about the differences between Function Compute 2.0 and 3.0, see Differences between 2.0 and 3.0
  1. Log on to the Function Compute console. In the top menu bar, select a Region.fig1

  2. In the left navigation pane, click Services. On the Services page, click Create Service.

  3. After the service is created, on the Function Management page, click Create Function.

  4. On the Create Function page, select "Create with Built-in Runtime". For the handler type, you must select "Event Request". Configure other parameters as needed. After you configure the parameters, click Create.image

  5. Next, test your function. For more information about how to configure the input parameters of the function, see Write a custom resolution function. Click Test Function to confirm that the function can be executed correctly and the returned data meets your expectations.

  6. Enter the function code. For more information about how to configure the function code, see Write a custom resolution function.fig1

  7. You can also choose Test Function > Configure Test Request. For more information about how to configure the input parameters, see Write a custom resolution function. Confirm that the function can be executed correctly and the returned data meets your expectations.fig2

  8. After the test is complete, click Deploy Code to confirm that the code is deployed.

  9. In the upper-right corner, click Publish Version. Enter the Description and click OK.Google Chrome 2025-04-07 16

Note

The system will generate a service version. The version number is incremented by one each time you publish a version. The latest version of a Function Compute service is not recommended by the custom resolution feature of HTTPDNS. Therefore, you must save the generated version number for later use.

At this point, the sample configuration in the FC 2.0 console is complete. You can go to the HTTPDNS console to add a function compute policy to configure the corresponding function.

To configure the newly created function compute service to take effect in the HTTPDNS function compute policy, see Add a function compute policy.