All Products
Search
Document Center

Elastic Compute Service:Create a command

Last Updated:Apr 01, 2026

Cloud Assistant lets you create reusable commands and run them on Elastic Compute Service (ECS) instances without logging in. Use commands to automate O&M tasks such as running scripts, polling processes, resetting passwords, installing or uninstalling software, updating applications, and applying patches.

Supported command types:

OSSupported types
LinuxShell, Python, Perl
WindowsBat, PowerShell

Limits

ResourceLimit
Commands per region500–50,000 (quota applies to your account; may increase with ECS usage)
Max Base64-encoded script size18 KB
Custom parameters per command20

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

Prerequisites

Before you begin, make sure that you have:

  • An Alibaba Cloud account with ECS access

  • (Optional) A resource group, if you want to control command permissions at the resource group level using Resource Access Management (RAM)

Create a command in the ECS console

Important

Do not include sensitive information — such as AccessKey pairs, passwords, or authorization codes — as plaintext in command content. Use custom parameters in the {{key}} format and supply values at runtime.

  1. Go to ECS console - ECS Cloud Assistant.

  2. In the top navigation bar, select the region and resource group where you want to create the command.

    Selecting a resource group lets you manage command permissions at the resource group level using RAM policies. For details, see Cloud Assistant command-specific sample custom policies and Classify resources into resource groups and grant permissions on the resource groups.

    地域

  3. In the upper-right corner of the ECS Cloud Assistant page, click Create/Run Command.

  4. In the Command Information section of the Create Command panel, configure the following parameters. Command type Select the type that matches your target instance OS: Command content Enter or paste the command. Make sure the syntax, logic, and algorithm are correct before saving. Example — archive a file to /backup on a Linux instance:

    • Run at Fixed Interval: Specify an interval using a rate expression (60 seconds–7 days). The interval is the time between consecutive executions, not the execution duration. For example, if the interval is 5 minutes and a run takes 2 minutes, 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 be longer than the command's timeout period.

    • Run Only Once at Specified Time: Set a specific date, time, and time zone. For example, May 17, 2022, 17:30:50 with (GMT+08:00) Asia/Shanghai runs the command once at that timestamp.

    • Run on Clock-based Schedule Cron Expression: Use a cron expression (accurate to seconds) and select a time zone. The minimum interval is 10 seconds and must exceed the timeout period. For example, 0 0 12 ? * WED 2022 with (GMT+08:00) Asia/Shanghai runs the command every Wednesday at 12:00:00 in 2022. For syntax details, see Cron expressions.

    Version requirements apply as follows: - `{{ACS::InstanceId}}` and `{{ACS::InstanceName}}`: When running a command on multiple instances, make sure the Cloud Assistant Agent on each instance meets the minimum version listed above. - `{{ACS::InvokeId}}`: Make sure the Cloud Assistant Agent version meets the minimum version listed above. - `{{ACS::CommandId}}`: When calling the RunCommand API, make sure the Cloud Assistant Agent version meets the minimum version listed above. To upgrade, see Install Cloud Assistant Agent.

    Command source

    OptionDescription
    Enter Command ContentWrite a new command.
    Select Saved CommandUse an existing saved command.
    ParameterDescriptionMinimum Cloud Assistant Agent version
    {{ACS::RegionId}}Region ID
    {{ACS::AccountId}}Alibaba Cloud account UID
    {{ACS::InstanceId}}Instance IDLinux >= 2.2.3.309, Windows >= 2.1.3.309
    {{ACS::InstanceName}}Instance nameLinux >= 2.2.3.344, Windows >= 2.1.3.344
    {{ACS::InvokeId}}Command task IDLinux >= 2.2.3.309, Windows >= 2.1.3.309
    {{ACS::CommandId}}Command IDLinux >= 2.2.3.309, Windows >= 2.1.3.309

    Execution plan

    OptionBehavior
    Immediate executionRuns as soon as you click Run or Run and Save.
    After the next startup of the systemRuns the next time the associated instances start.
    After each system startupRuns every time the associated instances start.
    Run on ScheduleRuns on a defined schedule. See schedule options below.

    Other parameters

    ParameterDescription
    Command NameA name for the command.
    Command DescriptionA description. Include the purpose of the command to simplify future management.
    UsernameThe OS user that runs the command on instances. Default: root on Linux, system on Windows. Run commands as a user with the minimum required privileges. See Run Cloud Assistant commands as a regular user.
    Execution PathThe directory in which to run the command. Default: /home (Linux root user home directory) or C:\Windows\system32 (Windows).
    TimeoutMaximum time allowed for the command to run, in seconds. Default: 60. Minimum: 10. Values below 10 are automatically set to 10.
    TagA tag (key-value pair) to classify and manage the command. If you click Run and Save, the tag is applied to both the command and the execution task. If you click Run, the tag is applied to the command only.
    #!/bin/bash
    OF=/backup/my-backup-$(date +%Y%m%d).tgz
    tar -cf $OF {{file}}

    In this example, {{file}} is a custom parameter. Set it to the file path at runtime (for example, /app/usrcredential). For more information, see View the system configurations of ECS instances. Use parameters Turn on Use Parameters to define custom parameters in the {{key}} format in your command content. You can specify up to 20 custom parameters per command. Cloud Assistant also provides built-in environment parameters that are resolved automatically at runtime: Run on Schedule options:

  5. In the Select Instance and Select Managed Instances sections, select the instances on which to run the command.

    A managed instance is a non-ECS server managed by Cloud Assistant. For details, see Alibaba Cloud managed instances.
  6. Click Save.

Create a command using Alibaba Cloud CLI

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

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

Key parameters:

ParameterExampleDescription
RegionIdcn-hangzhouThe region where the command is created.
NameupdateThe command name.
TypeRunShellScriptThe command type: RunShellScript (Linux Shell), RunBatScript (Windows Bat), or RunPowerShellScript (Windows PowerShell).
CommandContenteXVtIHVwZGF0ZSAteQ==The Base64-encoded command content.
DescriptionupdateThe command description.

For the full parameter reference, see CreateCommand.

Sample response:

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

What's next

After creating a command, view it on the My Commands tab. To run the command on specific instances, see Run a command.

If you enabled Use Parameters when creating the command, enter parameter values in the Command Parameters fields when running the command.