Alibaba Cloud provides the EdgeScript command-line interface (CLI). The EdgeScript CLI allows you to publish scripts that are created on premises to the staging environment and production environment. You can query, modify, and delete scripts in the staging and production environments by using the EdgeScript CLI. This topic describes how to use the EdgeScript CLI.

Work with the EdgeScript CLI

  1. Download the EdgeScript CLI.
  2. Configure your AccessKey ID and AccessKey secret.
    • Command:
      python ./ config --id=AK_ID --secret=AK_SECRET
      cat aliyun.ini
    • Response:
      access_key_id = 'Your AccessKey ID'
      access_key_secret = 'Your AccessKey Secret'
  3. Publish a script to the staging or production environment.
    ./ action=push_test_env domain=<domain> rule='{"pos":"<head|foot>","pri":"0-999","rule_path":"<the es code path>","enable":"<on|off>"}'
    ./ action=push_product_env domain=<domain> rule='{"pos":"<head|foot>","pri":"0-999","rule_path":"<the es code path>","enable":"<on|off>","configid":"<configid>"}'                    

    The following table describes the fields in the script.

    Field Required Feature
    rule Yes The content of the script.
    pos Yes The position where the script is executed. For more information, see Positions and priorities. Valid values:
    • head: The script is executed at the beginning of the request processing pipeline.
    • foot: The script is executed at the end of the request processing pipeline.
    pri Yes The priority of the script. You can prioritize only scripts that are executed in the same position. Valid values: 0 to 999.
    • 0: the highest priority.
    • 999: the lowest priority.
    rule_path Yes The path to the on-premises code file. Before you use the EdgeScript CLI to configure a script, you must upload the code file from your on-premises machine.
    enable Yes Specifies whether to enable or disable the script. Valid values:
    • on: yes
    • off: no
    configid Yes The configuration ID. You can all the DescribeDcdnDomainConfigs operation to query configuration IDs.
    Note The configuration ID is required if you want to modify a script. The configuration ID is not required if you want to create a script.
    brk No Specify whether to skip the subsequent scripts if the current script is executed. Valid values:
    • on: yes
    • off: no
    testip No The IP address of the client. By default, this field is empty. If you specify a client IP address, only requests sent from the specified IP address can trigger the execution of the script.
    option No The extensions. Only _es_dbg=signature is supported. You can use this field to enable response header debugging.
  4. Optional:You can perform the following operations based on your business requirements.
    Operation Command
    Query scripts in the staging or production environment
    ./ action=query_test_env domain=<domain>
    ./ action=query_product_env domain=<domain>
    Delete a script from the staging or production environment
    ./ action=del_test_env domain=<domain> configid=<configid>
    ./ action=del_product_env domain=<domain> configid=<configid>                  
    Publish scripts from the staging environment to the production environment or roll back scripts from the production environment to the staging environment
    ./ action=publish_test_env domain=<domain>
    ./ action=rollback_test_env domain=<domain>

For example, you can create, save, test, and publish the script that is used to block all M3U8 requests. For more information, see EdgeScript hands-on practices.

Real-time debugging

  1. Enable real-time debugging.
    • You can enable debugging in the console by setting the _es_dbg field. For more information, see Use EdgeScript to create a script.
    • You can also enable debugging by using the EdgeScript CLI to run the following script:
       ./ action=push_test_env domain=<domain> rule='{"pos":"<head|foot>","pri":"0-999","rule_path":"<the es code path>","enable":"<on|off>","configid":"<configid>", "option":"_es_dbg=123"}'
  2. Check debugging results.
    1. Initiate a request.
      The request carries the _es_dbg field. The value is set to the value of option, which is set in Step 1.
    2. Check the responses from the edge nodes.
      Pay attention to the following TRACE response: X-DEBUG-ES-TRACE-RULE-{Script ID}.
    3. Check the control flow of the script in the TRACE response. The format of the control flow is _flow number_function name(input parameter):return value{_execution time}.