All Products
Search
Document Center

Server Load Balancer:AScript syntax

Last Updated:Feb 26, 2024

This topic describes the AScript syntax. AScript is a type of programmable script supported by Application Load Balancer (ALB). You can use AScript to customize forwarding rules.

The following table describes the details of the AScript syntax.

Important

Do not use double quotation marks (") in AScript.

Syntax

Description

Annotation

All annotations must start with a number sign (#). Example: # this is annotation.

Identifier

  • Identifiers are case-sensitive. An identifier can contain letters, digits, and underscores (_). It cannot start with a digit.

  • All names of built-in variables, custom variables, built-in functions, and custom functions must comply with the identifier conventions.

Data type

  • String

    Literal constants: Use a pair of single quotation marks (') to quote a literal constant, for example, 'hello, AScript'.

  • Numeric

    Literal constants: decimal numbers, for example, 10, -99, or 1.1.

  • Boolean

    Literal constants: true or false.

  • Dictionary

    Literal constants:

    • []: an empty string.

    • ['key1', 'key2', 100]:

      • 1 -> 'key1'

      • 2 -> 'key2'

      • 3 -> 100

    • ['key1' = 'value1', 'key2' = 1000]

      • 'key1' -> 'value1'

      • 'key2' -> 1000

Variable

  • Definition

    A variable is a symbolic name associated with a value that may change.

  • How to use

    • Both built-in and custom variables are referenced by using their names.

      • Reference a built-in variable: host.

      • Reference a custom variable: seckey.

    • To specify that a variable is a built-in variable, add a dollar sign ($) before the variable name.

      Reference a built-in variable: $host.

    • A custom variable and a built-in variable cannot use the same name.

      For more information about built-in variables, see Built-in variables.

Operator

  • =: the assignment operator.

    • Example: seckey = 'ASDLFJ234dxvf34sDF'

    • Example: seckeys = ['key1', 'key2']

  • -: the minus operator.

    Example: inum = -10

  • Built-in functions are used to process different types of data. No additional operators are provided. For more information about built-in functions, see AScript functions.

Clause

  • Condition clause

    if condition {   
       ...
    }
    
    if condition1 {   
       if condition2 {
            ...
       }
    }
    
    if condition {
       ...
    } else {
       ...
    }
  • Clause descriptions

    • A condition clause contains the following elements:

      • Literal constant

      • Variable

      • Function call

    • Body

      • The body can be empty.

      • Multiple statements are allowed. Enter only one statement on each line.

    • Statement nesting is allowed.

    • Coding style

      The opening brace ({) must follow if condition on the same line.

Function

  • Syntax

    def Function name(Parameter list) {
        ...
    }
  • Descriptions

    • Parameter list

      • The parameter list can be empty.

      • Multiple parameters are allowed. Separate parameters with commas (,).

    • Body

      • The body can be empty.

      • Multiple statements are allowed. Enter only one statement on each line.

      • The return values support the return clause.

    • Coding style

      The opening brace ({) must follow def Function name(Parameter list) on the same line.

  • Function call

    You must use Function name(Parameter list) to call built-in and custom functions.