All Products
Search
Document Center

Elastic Compute Service:Create a command

Last Updated:Aug 17, 2026

Cloud Assistant commands let you quickly perform routine tasks on Elastic Compute Service (ECS) instances, such as running automated O&M scripts, polling processes, resetting user passwords, installing or uninstalling software, updating applications, and installing patches. A command can be a Windows PowerShell script, a Windows Bat script, or a Linux Shell script, and it supports custom parameters that let you set variable values.

Limitations

Resource Limit
Commands per region 500–50,000 (quota per account; may increase with ECS usage)
Max Base64-encoded script size 18 KB

To view or increase your quota, see Manage quotas. Include a detailed reason in your request to improve approval chances.

Procedure

Create a command in the ECS console

  1. Go to the ECS Cloud Assistant page.

  2. In the top navigation bar, select a region and resource group.

    After you assign the command to a resource group, you can manage command permissions at the resource group level. Add the required access policies to that resource group. For the access policies that apply to Cloud Assistant commands and for resource group authorization, see Cloud Assistant command-specific sample custom policies and Classify resources into resource groups and grant permissions on the resource groups.
  3. On the ECS Cloud Assistant page, click Create/Run Command.

  4. In the Command Information section, configure the command. Command type Select the type that matches your target instance OS. Command content Enter or paste the command. Verify the syntax, logic, and algorithm before saving. Example — archive a file to /backup on a Linux instance:

    • Run at Fixed Interval: Set an interval (60 seconds–7 days) using a rate expression. The interval is the gap between consecutive executions, not the execution duration. For example, a 5-minute interval with a 2-minute run means the next run starts 3 minutes after the previous run ends. The first run starts after the interval elapses from task creation. > Note: The interval must exceed the command's timeout period.

    • Run on Clock-based Schedule Cron Expression: Specify a cron expression (accurate to seconds) and a time zone. Minimum interval: 10 seconds (must exceed the timeout period). Example: 0 0 12 ? * WED 2022 with (GMT+08:00) Asia/Shanghai runs every Wednesday at 12:00:00 in 2022. See Cron expressions.

    Execution plan

    Option Behavior
    Precheck only Prechecks the request without applying the command. The precheck covers the request parameters, the execution environment of the instances, and the status of Cloud Assistant Agent.
    Run on schedule Runs the command as a scheduled task. See the options that follow.

    Other parameters

    Parameter Description
    Command Name A name for the command.
    Command Description A description of the command purpose.
    Username The OS user that runs the command. Default: root (Linux), system (Windows). Use the minimum required privileges. See Run Cloud Assistant commands as a regular user.
    Execution Path The directory in which the script runs on the instance. Default value: /root for Linux and C:\Windows\system32 for Windows. To make sure that the script runs in the expected directory, add a cd command at the beginning of the script.
    Timeout The maximum execution time. Valid values: 10 to 86,400 seconds (24 hours). Default value: 60 seconds. A value below 10 is set to 10.
    Task termination mode

    Specifies how the task ends when you stop it.

    • Script Process: terminates the script process.

    • Process Tree: terminates the process tree, which is the script process and all child processes that it creates.

    Command content: you can turn on Use Parameters. After Base64 encoding, the command content must not exceed 18 KB if you choose Run and Save, or 24 KB if you choose Run.

    Custom parameters: define parameters in the {{parameter}} format and assign values manually. Custom parameters support dynamic values and let you reuse one value in several places.

    Built-in parameters: Cloud Assistant provides built-in parameters that are replaced automatically at run time and need no manual assignment, such as {{ACS::RegionId}} for the region ID and {{ACS::InstanceId}} for the instance ID.

    #!/bin/bash
    # Example
    # {{name}} is a custom parameter. Assign a value to it after you finish writing the command content.
    echo {{name}}
    
    # {{ACS::RegionId}} is a built-in parameter and needs no manual assignment.
    echo {{ACS::RegionId}}
  5. In Select Instance or Select Managed Instances, select the target instances. You can select multiple instances, up to 100 at a time.

  6. Click Save.

Create a command using Alibaba Cloud CLI

Request example

Call CreateCommand to create a command. The following example creates a command named update that updates the OS on Linux instances.

aliyun ecs CreateCommand --RegionId 'cn-hangzhou' \
--CommandContent 'eXVtIHVwZGF0ZSAteQ==' \
--Type 'RunShellScript' \
--Name 'update' \
--Description 'update' \
--output cols=CommandId
Replace the values in single quotes with your actual values.

The following table describes the key parameters. For the full parameter reference, see CreateCommand.

Parameter Example Description
RegionId cn-hangzhou The region.
Name update The command name.
Type RunShellScript The command type: RunShellScript (Linux Shell), RunBatScript (Windows Bat), or RunPowerShellScript (Windows PowerShell).
CommandContent eXVtIHVwZGF0ZSAteQ== The Base64-encoded command content.
Description update The command description.

Response example

CommandId
---------
c-hz018qng4on****

Next steps

After you create a command, you can view its details on the My Commands tab. To run the command on specific instances, see Run a command.

If the command uses parameters, enter the parameter values in the Command Parameters column when you run the command.