AScript allows you to create programmable scripts for standard Application Load Balancer (ALB) instances. The letter "A" in AScript stands for agile, application-oriented, and Alibaba Cloud. AScript provides powerful customization capabilities that allow you to perform secondary development when the standard configurations in the ALB console cannot meet your business requirements.

What is AScript?

AScript provides easy-to-learn syntax and a large number of functions that allow you to customize your ALB configurations.

AScript provides encapsulation-free functions, built-in variables, and the if-else statement. You can use variables and functions to customize forwarding rules, which enable your business to quickly adapt to changes.

For more information about the AScript syntax, see AScript syntax.

Use scenarios

Scenario Description
Hotlink protection You can use AScript to customize authentication algorithms, user-agent blacklists, and referer whitelists. You can use AScript 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 implement access control on 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 requests to the desired resources. If your website supports different languages, requests destined for the website are redirected to the URLs that point to the content written in the requested language. For example, requests that require the English or German language are redirected from the China site to the English or German site.

Billing and pricing

Only standard ALB instances support AScript. Whether you are charged for using AScript is based on the number of effective lines of code and forwarding rules configured for an ALB instance.
  • If the number of effective lines of code does not exceed 20, the number of rule evaluations is calculated based on the following formula:
    Rule evaluations = QPS × (Number of forwarding rules - 10). In this formula, 10 is the number of forwarding rules that you can use free of charge.
  • If the number of effective lines of code exceeds 20, the number of rule evaluations is calculated based on the following formula:
    Rule evaluations = QPS × (Number of forwarding rules - 10 free-of-charge forwarding rules) + QPS × (Number of effective lines of code - 20). In this formula, 10 is the number of forwarding rules that you can use free of charge and 20 is the number of effective lines of code that you can use free of charge.
Example of calculating rule evaluations
100 new connections are established to an ALB instance per second. Each connection lasts 3 minutes. Four requests are sent through each connection per second. 20 forwarding rules and 30 lines of code are configured. The number of LCUs consumed is calculated based on the following formulas:
  1. 100 new connections are established per second. Four requests are sent through each connection per second. Therefore, the QPS value is:
    100 × 4 = 400
  2. 20 forwarding rules and 30 lines of code are configured. Therefore, the number of rule evaluations is:
    (20 - 10) × 400 + (30 - 20) × 400 = 8000
  3. Each 1,000 rule evaluations consumes one LCU per second. Therefore, the total number of LCUs consumed is:
    8000÷1000=8

For more information about how to calculate LCU consumption based on rule evaluations, see LCU fee.