Enable edge computing

更新时间:
复制 MD 格式

Dynamic Content Delivery Network (DCDN) provides edge computing through EdgeRoutine (ER) and EdgeKV. Deploy services or lightweight applications to points of presence (POPs) closer to your users to reduce response latency. These services run as serverless instances — Alibaba Cloud manages and schedules resources for you.

Note

EdgeRoutine is currently in beta and is available only to select customers. If the daily peak bandwidth of your or DCDN service exceeds 500 Mbps, you can fill out an application to request access. After your application is approved, the EdgeRoutine menu item appears in the navigation pane.

ER

ER is a JavaScript runtime environment for implementing logic at the edge. Your code runs on any POP in the Alibaba Cloud global network, serving users from the nearest POP to significantly reduce response times.

Enable the EdgeRoutine service

  1. Log on to the DCDN console.

  2. In the navigation pane on the left, click EdgeRoutine.

  3. Click Enable EdgeRoutine > Activate Now to enable the service.

Create your first routine

Step 1: Create and configure a routine

  1. Log on to the DCDN console.

  2. In the navigation pane on the left, click EdgeRoutine.

  3. If you are using EdgeRoutine for the first time, you must first create a subdomain.

    1. On the EdgeRoutine page, click Create Subdomain.

      image.png

    2. In the Create Subdomain dialog box, enter a subdomain name.

      Note
      • A subdomain acts as a repository for all your routines. The subdomain cannot be changed once it is created.

      • The subdomain is a unique identifier for each user and forms part of the routine ID.

      • The name must contain only lowercase letters, digits, and hyphens (-), and must be at least two characters long, for example, subdomain-name.

    3. Click OK.

  4. On the EdgeRoutine page, click Create Routine.

    Create Routine

    Parameter

    Description

    Routine Name

    Enter a name for the routine.

    Note

    The name can contain lowercase letters, digits, and hyphens (-). The name cannot be less than 2 characters in length. Example: routine-name. The routine name cannot be modified after it is created.

    Description

    (Optional) A description of the routine.

    Specification

    The maximum CPU time for a single routine execution, excluding I/O wait time for network responses. The maximum runtime is 120 seconds, and the available memory is 128 MB. Fees vary based on the selected specification. The 50 ms specification is selected by default. For more information, see Billing of EdgeRoutine.

    • CPU Time Slice for Individual Requests: 5 ms

    • CPU Time Slice for Individual Requests: 50 ms (Default)

    • CPU Time Slice for Individual Requests: 100 ms

  5. After creating the routine, click Details in the Actions column to open its details page. Each environment (production, staging, and optional canary) has an independent configuration that you can modify.

    Parameter

    Description

    Routine Specifications

    The maximum CPU time for a single routine execution, excluding I/O wait time for network responses. The maximum runtime is 120 seconds, and the available memory is 128 MB. The 50 ms specification is selected by default.

    • CPU Time Slice for Individual Requests: 5 ms

    • CPU Time Slice for Individual Requests: 50 ms (Default)

    • CPU Time Slice for Individual Requests: 100 ms

    Domain Name Whitelist

    • Specifies the domains that can be associated with this routine.

    • Wildcard domains are supported.

    • By default, the domain name whitelist is empty, allowing any domain to be associated with the routine.

    Note

    For example, if you add example.com to the whitelist, only requests from example.com can trigger this routine. Requests from other domains are rejected by the routine.

Step 2: Associate domain names with a routine

A routine requires a domain to serve as an entry point for client requests. You can use a domain accelerated by Alibaba Cloud CDN or DCDN. After you create and configure the routine, you must associate your or DCDN domain with it. Client requests to this domain will then trigger the routine. The procedure varies depending on the console where your domain is hosted.

  1. Log on to the DCDN console.

  2. In the left-side navigation pane, click Domain Names.

  3. On the Domain Names page, find the target domain name and click Configure.

  4. In the navigation pane on the left for the domain, click EdgeRoutine.

  5. On the EdgeRoutine page, enable the feature and configure the Routine ID.

    EdgeRoutine

    Parameter

    Description

    Routine ID

    The unique identifier for each routine. The format is routine-name.subdomain.

    Note

    In the navigation pane on the left of the DCDN console, click EdgeRoutine. You can find the ID of the corresponding routine on the Function page.

    image.png

    Trigger Mode

    Requests to the or DCDN domain trigger the routine. Two modes are available:

    • Redirect: Requests to the or DCDN domain are fully handled by the routine. You can write your own code to directly respond to the client, read from the cache by using the Cache API, or fetch content from the origin.

    • Bypass: Requests to the or DCDN domain only trigger the routine execution, and then proceed with the regular or DCDN configuration to redirect to origin. This mode is suitable for scenarios such as authentication or logging.

    Redirect to Origin if Error Occurs

    • Yes: If a routine execution fails, the point of presence (POP) forwards the client request to the origin server of the or DCDN domain. This allows you to implement fallback and disaster recovery mechanisms on your origin server.

    • No: If a routine execution fails, the POP returns a 5xx status code directly to the client.

      Note
      • The first time you use a routine, we recommend that you set the Redirect to Origin if Error Occurs parameter to No. You can use the HTTP 5xx status code that is returned to troubleshoot issues.

      • If an exception occurs, you are charged for the number of back-to-origin requests. The percentage of abnormal back-to-origin requests is very low and can be ignored.

Step 3: Develop and debug a routine

  1. Log on to the DCDN console.

  2. In the navigation pane on the left, click EdgeRoutine.

  3. Select the routine that you created and click Details.

  4. On the Details page, select the Code tab to develop your EdgeRoutine in JavaScript. The editor includes a default "Hello World" example.Code

  5. After writing the code, click Release to Staging Environment. You can then use any of the provided staging environment IP addresses to map in your local hosts file for testing and debugging the routine.

    Note

    To test, modify the hosts file on your local machine to map the domain to one of the provided staging IP addresses. For example: 10.10.10.10 example.com. Replace the IP address with one of the provided IPs and the domain name with the or DCDN domain associated with the routine.

Step 4: Save a version

After debugging the code, on the Code tab, click Save as Version.Test

Step 5: Publish a version

  1. On the Details page, select the Versions tab. Choose a version ID and click Release in the Actions column.

  2. Select the environment to publish to: Staging Environment, Production Environment, or Canary Environment.

    Note

    We recommend that you release a routine to the canary environments before you release it to the production environments.

  3. Click OK. This deploys the version's code to all POPs in the selected environment.

EdgeKV

EdgeKV is an edge key-value storage service designed for low-frequency writes and high-frequency reads by ER. Data added to EdgeKV is automatically synchronized to POPs around the world, and ER reads the data from the same POP.

Activate EdgeKV

You must activate EdgeKV before you can use it.

  • Log on to the DCDN console.

  • In the left-side navigation pane, click EdgeKV, and then click Activate Now.

1

Manage key-value data in EdgeKV

Create a namespace

Note

Namespaces are isolated from each other. You can create up to 10 namespaces.

  1. Log on to the DCDN console.

  2. In the left-side navigation pane, choose Edge Computing > EdgeKV. On the page that appears, click Create Namespace and follow the on-screen instructions to configure the Namespace Name and Description parameters.

    Note

    The Namespace Name parameter corresponds to the namespace parameter in the built-in API operations of ER.

    Create namespace

  3. Click OK.

Manage key-value data

  1. Log on to the DCDN console.

  2. In the namespace list, find the namespace that you want to manage and click Manage in the Actions column.

  3. Click Add Key-value and follow the on-screen instructions to configure the Key and Value parameters.8

  4. Click OK.

  5. Optional. After you add data, click Modify, View, or Delete to manage the data.