This topic describes how to activate and use Edge Routine in the Edge Security Acceleration (ESA) console.
Prerequisites
A website has been added to ESA and is in the Active state. For information about how to add a website, see Add a website.
An SSL/TLS certificate is configured for the website before you access Edge Routine over HTTPS. For information about how to configure an SSL/TLS certificate, see Configure edge certificates.
Step 1: Create a routine
Log on to the ESA console.
In the left-side navigation pane, choose
.On the Edge Routine page, click Create Routine.
In the Select Template step of the Create Routine page, select a template provided by ESA to generate routine code and click Next.
In the Configure Routine step, configure the parameters according to the following table and click OK.
Parameter
Description
Routine Name
Enter a routine name.
NoteThe name must be 2 to 41 characters in length and can contain lowercase letters, digits, and hyphens (-). The name must start with a lowercase letter and cannot end with a hyphen. Example:
routine-name
. After a routine is created, you cannot change the name of the routine.Specification
Select a specification. The specification specifies the maximum CPU time slice for a single execution of a routine. The I/O time to wait for network responses is not included in the CPU time slice. The maximum response time is 120 seconds. The available memory size is 128 MB. Fees vary based on routine specifications. For more information about billing, see Billing rules. Valid values:
CPU Time Slice for Individual Requests: 5ms (default)
CPU Time Slice for Individual Requests: 50ms
CPU Time Slice for Individual Requests: 100ms
Description
Optional. Enter a description for the routine.
Code Preview
Preview the routine code.
Step 2: Configure a trigger
Edge Routine of ESA allows you to use triggers to define the calling methods of scripts. You can associate a domain such as er.example.com
with a routine. This way, all the traffic destined for the domain is directed to the routine. You can also add a route to specify matching URLs in a routine. In this case, a portion of the traffic destined for the specified URLs is directed to the routine. For example, if you add the er.example.com/test/path/
route in a routine, the traffic to er.example.com/test/path/
is directed to the routine.
Log on to the ESA console.
In the left-side navigation pane, choose
.On the Edge Routine page, find the routine that you created and click View Details in the Actions column.
On the routine details page, click the Triggers tab. You can associate a domain name or add a route to direct traffic destined for a specific domain to the routine.
Step 3: Develop and debug a routine
Log on to the ESA console.
In the left-side navigation pane, choose
.On the Edge Routine page, find the routine that you created and click View Details in the Actions column.
On the details page that appears, click the Code tab and develop the routine by using JavaScript (ES6 syntax).
Debug the routine code. ESA provides a debugging environment. After you write the code, you can click Save to Debugging Environment on the Code tab. Then, you can construct an HTTP request method, header, and body on the right side of the Code tab and click Request. ESA directly returns a response after the routine processes the request.
After you debug the code, click Save as Version. On the Deployment tab, view the generated version.
Click Publish and select Test Environment. The code takes effect on the test POP. You can add a binding entry to your local hosts file. This allows you to initiate a request from a real client and view the response on the client.
NoteWe recommend that you deploy the version to all the canary environments before you deploy the version to the production environments.
Step 4: Release the official version
On the details page that appears, click the Deployment tab. Click Release in the Actions column of the desired version.
Select Production Environment. Click Release.
Click OK. Then, code of this version is deployed to all POPs of the production environments.