All Products
Search
Document Center

Server Load Balancer:AScript

Last Updated:May 12, 2025

AScript is a programmable script feature that offers powerful customization capabilities, enabling you to perform secondary development on forwarding rules when the standard configurations in the ALB console do not meet your business requirements.

What is AScript?

AScript provides easy-to-learn syntax and many functions that allow you to create custom ALB configurations.

image

AScript provides encapsulation-free functions, built-in variables, and the if-else statement. You can use variables and functions to create custom forwarding rules. This way, your business can quickly adapt to changes.

For details about the AScript syntax, see AScript syntax.

Use scenarios

  • Hotlink protection

    You can use AScript to customize authentication algorithms, User-Agent (UA) blacklists, and Referer whitelists. AScript allows you to customize the authentication logic and authenticate requests based on request parameters, cookies, or algorithms. This helps you protect your resources against attacks.

  • Access control based on whitelists or blacklists

    You can use AScript to configure an IP blacklist or whitelist to control access from clients.

  • Request and response header customization

    You can use AScript to modify variables, such as request and response headers, based on your business requirements.

  • Request rewrites and redirects

    You can use AScript to rewrite request URIs and file extensions, add URI prefixes, and perform 302 redirects. This way, you can rewrite requests or redirect them to the desired resources.

    A common use case is that your website supports different languages. With Ascript, requests destined for the website can be redirected to the URLs that point to the content written in the requested language. For example, requests that require English or German are redirected from the China site to the English or German site, respectively.

Billing

For information about how the number of rule evaluations affects the Load Balancer Capacity Unit (LCU) fee, see Billing rules.

How it works

Working principles

Same as standard forwarding rules, AScript is used to define how requests are processed by ALB.

When a request reaches ALB, ALB processes the request based on the forwarding rules configured in the ALB console. AScript can execute scripts to process the request before or after forwarding rules are applied.

Scripts are executed based on the following model:

  • AScript executes scripts to perform various operations. Operations are triggered only when the conditions in scripts are met.

  • You can specify the position where a script is executed and the priority of the script in a request processing pipeline.

  • Scripts are managed based on listeners.

Execution positions

You can configure scripts to be executed before or after an inbound forwarding rule is applied, or before an outbound forwarding rule is applied. The operations that can be performed vary based on the execution position:

  • Before or after an inbound forwarding rule: renaming frequently used files, converting file extensions to lowercase letters, adding URI prefixes, and rewriting file extensions

  • Before an outbound forwarding rule: renaming frequently used files

Execution status

When configuring a script on the Add Script or Edit Script page, in the Advanced Settings section, you can select If a request carries the _es_dgb parameter and the value of the parameter is the specified key, the debug header is added to the response. The header carries records of script execution.

Parameters defining the execution status of a script are described as follows:

  • Status ID: the unique identifier for the execution status of a script, in the as-**** format.

    The following table describes the valid values of the status ID:

    Status ID

    Description

    Empty

    Indicates the script is not executed.

    0

    Indicates the condition is met.

    This ID is returned when if condition {} is specified in the script and the condition is met.

    1

    Indicates the condition is not met.

    This ID is returned when if condition {} is specified in the script but the condition is not met, or if condition {} is not specified.

    2

    Indicates script execution fails.

  • Execution time:

    • Unit: microseconds.

    • Default value: -1.

    • Execution time displayed on the web interface:

      • Tier 1: 0 to 100 µs

      • Tier 2: 100 to 500 µs

      • Tier 3: 500 to 1000 µs

      • Tier 4: 1000 to 5000 µs

      • Tier 5: 5000 to 20000 µs

      • Tier 6: 20000 to 50000 µs

      • Tier 7: above 50000 µs

  • Execution suspended:

    Default value: -1.