You can use Cloud Assistant scripts to perform routine tasks for ECS instances. These tasks are: running automated O&M scripts, polling the processes, resetting user passwords, installing or uninstalling software, updating applications, and installing patches. Script types can either be bat or PowerShell for Windows, or shell for Linux. You can also specify custom parameters as variables.

Background information

  • You can keep a maximum of 100 Cloud Assistant scripts within an Alibaba Cloud region. The quota of scripts may increase with your ECS usage.
    Note You can also call the DescribeAccountAttributes operation with the AttributeName.N parameter set to max-axt-command-count to query the maximum number of Cloud Assistant scripts that you can retain within a region.
  • A script cannot exceed 16 KB in size after being encoded in Base64.
  • A maximum of 20 custom parameters can be specified in a Cloud Assistant script.
  • When you create a script, you must check whether the syntax, logic, or algorithm of the script is correct.

    For example, assume that you have created the /backup directory (mkdir /backup) on the instance, the following shell script archives a file in this directory.

    #! /bin/bash
    OF=/backup/my-backup-$(date +%Y%m%d).tgz
    tar -cf $OF {{file}}
    Note In this example, {{file}} is a custom parameter. When you run the script, you can set its value to the name of the file to be archived, such as /app/usrcredential. Custom parameters can be used in scenarios of dynamic values and multi-purpose values. We recommend that you specify custom parameters for data that is security sensitive or changes with the environment, such as AccessKey pairs, instance IDs, authorization codes, time parameters, and key system files.

Procedure in the console

  1. Log on to the ECS console and navigate to the Cloud Assistant page.
  2. In the top navigation bar, select a region.
  3. Click Create or Run Script and configure parameters.
    1. Set Script Type.
      • Linux instances: shell.
      • Windows instances: bat or PowerShell.
    2. Edit the existing content or paste new content in the Script field.
      For more information about shell script examples, see View instance configurations.
    3. Determine whether to turn on Use Parameters.
      If you turn on Use Parameters, you can specify custom parameters in the {{key}} format in the Script field.
    4. Enter a script name in the Script Name field.
    5. Enter a script description in the Script Description field.
    6. Enter an execution path in the Execution Path field.
      • The default execution path of shell scripts is the /home directory of the root user.
      • The default execution path of bat and PowerShell scripts is the directory where the Cloud Assistant client is installed, such as C:\ProgramData\aliyun\assist\$(version).
    7. Set the allowed longest timeout period for Timeout. Default value: 60 seconds.
    8. Click OK.
    Create a script

Procedure by using CLI

  • Sample request:

    Call the CreateCommand operation to create a Cloud Assistant script named test. The script content is echo 123 and is encoded as a Base64-encoded plaintext. If the target instances are Windows instances, set Type to RunBatScript or RunPowershellScript.

    aliyun ecs CreateCommand --RegionId TheRegionId --CommandContent ZWNobyAxMjM= --Type RunShellScript --Name test --Description test --output cols=CommandId
  • Sample response:
    --------- c-hz0b8osxk8a***

What to do next

Run a script

Note If you turn on Use Parameters when you create the script, enter the parameter values in the Script Parameters field.