Understand Alibaba Cloud CLI command parameters

Updated at:
Copy as MD

Alibaba Cloud CLI command parameters are classified into global flags that control CLI behavior and business parameters that are passed to subcommands. This topic describes how to view available parameters, format parameter values of various data types, and use the auto-completion feature.

Prerequisites

Parameter types

A CLI command consists of a command, a subcommand, and parameters:

aliyun <command> <sub-command> [parameters]

Parameters are classified into two types:

  • Global Flags: Control the behavior of the CLI itself, such as region selection, output format, and pagination.

  • Business parameters: Request fields that are passed to subcommands. Business parameters vary by operation.

In the following example, --help is a Global Flag and --RegionId is a business parameter:

aliyun ecs DescribeInstances --help
aliyun ecs DescribeInstances --RegionId cn-hangzhou

Global Flags

The parameter table in this topic applies to cloud product OpenAPI calls. For parameters of other commands, refer to their respective --help output.

Flag

Type

Description

--region

string

Specifies the region ID, such as cn-hangzhou. This flag overrides the default region in the configuration.

--endpoint

string

Specifies the API endpoint URL. In most cases, you do not need to manually set this flag.

--cli-query

string

Filters output by using a JMESPath expression.

--pager

string

Automatically merges all pages of paginated API results.

--cli-dry-run

bool

Constructs and previews the request without sending an API request. It does not verify permissions, server-side business validity, or business-required conditions. It is mutually exclusive with --pager, --waiter, and --quiet.

--cli-ai-mode

bool

Enables AI mode for the current command: help and error output become machine-readable JSON, and an AI identifier is appended to the User-Agent of API requests. For detailed behavior and configuration, see AI Mode.

--yes / -y

bool

Skips the confirmation prompts triggered by Safety Policy. This flag is suitable for non-interactive scripts or AI Agent scenarios. --yes cannot bypass a deny rule in Safety Policy.

--cli-output

string

Sets the output format of help information and local errors. At the help layer, only json is supported, which facilitates parsing by scripts and AI Agents. This validation does not describe output-parameter rules for ordinary API calls.

--language

string

Specifies the language of CLI help and output messages. Valid values: en (English) / zh (Chinese).

--log-level

string

Sets the log output level for debugging and troubleshooting. Valid values: DEBUG / INFO / WARN / ERROR

-q / --quiet

bool

Quiet mode: suppresses the API response output. This flag is suitable for scripting and CI/CD scenarios.

-h / --help

bool

Displays help information. Cannot be combined with --help-all or --help-search.

--help-all

bool

Displays the complete help information of the current command level, including all subcommands and parameters. Can be combined with --help-search.

--help-search

string

Searches for commands and parameters that match a keyword at the current command level, such as --help-search configure.

Note

--help-all, --help-search, and --cli-output are used to view and retrieve help information. In an Agent environment, help may be truncated; use --help-all to view the complete list. For detailed usage, see Command structure.

Business parameters

Business parameters are request fields that are passed to subcommands. Different operations have different business parameters.

aliyun ecs DescribeInstances --RegionId cn-hangzhou --cli-dry-run

The data types of business parameters are defined by APIs. Common types include:

  • String: A text string, such as an instance ID or name.

  • Integer: A whole number, such as a page number or count.

  • Boolean: A Boolean value of true or false.

  • Array / JSON: An array or JSON object, such as a list of disk IDs or a tag object.

Discover parameters

You can view the parameters that a command supports by using CLI help information or the online OpenAPI portal.

Use CLI help information

Append --help to a command to view its available parameters and descriptions. For example:

aliyun ecs DescribeInstances --help

Help output:

Description: Queries a list of instances based on specified request conditions and retrieves the associated detailed information of the instances

API Version: 2014-05-26

Usage:
  aliyun ecs DescribeInstances [parameters]
......

The help for the configure command shows its subcommands and options:

aliyun configure --help

Help output:

configure credential, AI Mode and settings

Usage:
  aliyun configure --mode {AK|RamRoleArn|EcsRamRole|OIDC|External|CredentialsURI|ChainableRamRoleArn|CloudSSO|OAuth|BearerToken} --profile <profileName> [--config-path <configPath>]

Sample:
  aliyun configure --mode OAuth  (Recommended)

Commands:
  sso             Manage shared CloudSSO sessions
  get             print configuration values
  set             set config in non interactive mode
  list            list all config profile
  delete          delete the specified profile
  switch          switch default profile
  safety-policy   manage safety policy and human-in-the-loop rules
  ai-mode         manage global AI mode and User-Agent for API calls
  telemetry       manage CLI telemetry
  plugin-settings manage global plugin system settings
......

Use the OpenAPI portal

The Alibaba Cloud OpenAPI portal allows you to debug APIs online and automatically generates CLI command examples. For more information, see Generate and run CLI commands with OpenAPI Explorer.

Parameter values

The way you pass parameter values varies by data type and operating system environment.

Common type parameter values

Data type

Format

Example

Integer

Pass the value directly without quotes.

--PageSize 10

String

Pass the value directly if it does not contain special characters. Enclose the value in quotes if it contains special characters.

--InstanceId i-bp1234****

Boolean

A flag that enables or disables a feature. For example, including --cli-dry-run enables the feature, and omitting it disables the feature.

--cli-dry-run

String list

Separate multiple values with commas and enclose the entire list in quotes.

--ImageId 'm-bp1****,m-bp2****'

JSON array

A JSON-formatted string enclosed in quotes.

--DiskIds '["d-bp1****","d-bp2****"]'

Date

ISO 8601 format: YYYY-MM-DDThh:mm:ssZ

--StartTime 2024-11-28T15:00:00Z

Different operating systems and terminal environments handle quotes differently. When passing parameter values that contain special characters, use the following quoting rules:

Environment

General quotes

Quotes for the --body flag

Linux / macOS

Single quotes ''

Double quotes ""

Windows Command Prompt

Double quotes ""

Double quotes ""

Windows PowerShell

Single quotes ''

Single quotes ''

JSON parameter values

Some command parameters require values in JSON format. The choice of outer quotes and inner quotes varies by operating system.

JSON arrays

  • Linux / macOS: Use single quotes for the outer layer and double quotes for inner values.

    aliyun ecs DescribeDisks --DiskIds '["d-bp1****","d-bp2****","d-bp3****"]' --RegionId cn-hangzhou
  • Windows (Command Prompt and PowerShell): Use double quotes for the outer layer and single quotes for inner values.

    aliyun ecs DescribeDisks --DiskIds "['d-bp1****','d-bp2****','d-bp3****']" --RegionId cn-hangzhou

JSON objects

When a parameter value is a JSON object, enclose each JSON object in braces {} and separate keys and values with colons :.

  • Linux / macOS:

    aliyun slb AddBackendServers --LoadBalancerId lb-bp1**** --BackendServers '[{"ServerId":"i-bp1****"},{"ServerId":"i-bp2****"}]'
  • Windows (Command Prompt and PowerShell):

    aliyun slb AddBackendServers --LoadBalancerId lb-bp1**** --BackendServers "[{'ServerId':'i-bp1****'},{'ServerId':'i-bp2****'}]"

Values that contain special characters

Values that start with a hyphen (-)

When a parameter value starts with -, the CLI may misinterpret it as another parameter name:

aliyun ecs AuthorizeSecurityGroup --SecurityGroupId 'sg-bp67acfmxazb4p****' --Permissions.1.PortRange "-1/-1" --method POST --force

Use an equal sign to connect the parameter name and value to resolve this issue:

aliyun ecs AuthorizeSecurityGroup --SecurityGroupId 'sg-bp67acfmxazb4p****' --Permissions.1.PortRange=-1/-1 --method POST --force

Shell special characters

When parameter values contain shell special characters ($, `, \, spaces, and so on), you must enclose them in quotes. On Linux / macOS, use single quotes to prevent the shell from interpreting special characters. On Windows Command Prompt, use double quotes.

# Linux/macOS/PowerShell
aliyun ecs DescribeImages --ImageName 'Example Image'
# Windows CMD
aliyun ecs DescribeImages --ImageName "Example Image"

# Linux/macOS
aliyun xxx --param '$literal_dollar'

Load parameter values from a file

When a parameter value is long, such as a certificate or a large JSON payload, it is more convenient to load the value from a local file.

--body and --body-file

Some APIs require a request body in JSON format. Use --body to pass a JSON string directly, or --body-file to load it from a local file. For example, request.json stores the request body content:

aliyun cs ModifyClusterNodePool --ClusterId c1234**** --NodepoolId np5678**** --body-file request.json
Note

--body-file is read directly by the CLI and works on both Windows and Linux / macOS.

Shell command substitution

In bash or zsh, you can use shell command substitution to pass file content as a business parameter value. For example, disk-ids.json contains the following JSON array of disk IDs:

["d-bp1****","d-bp2****","d-bp3****"]
aliyun ecs DescribeDisks --DiskIds "$(cat disk-ids.json)" --RegionId cn-hangzhou
Note

Shell command substitution is supported only in bash or zsh.

Command auto-completion

Alibaba Cloud CLI supports command auto-completion. After you enable this feature, you can press Tab to auto-complete product names, operation names, and parameter names.

Note

Auto-completion is only supported in bash or zsh environments on Linux and macOS systems. Auto-completion covers product names, operation names, and parameter names, but does not cover parameter values.

Run the following command to enable auto-completion:

aliyun auto-completion

After you enable auto-completion, run the following command to apply the configuration immediately, or restart the terminal:

# bash
source ~/.bash_profile

# zsh
source ~/.zshrc

To verify that auto-completion is working, type aliyun and press Tab. If a list of candidate commands appears (such as configure), auto-completion is enabled.

To disable auto-completion, run:

aliyun auto-completion --uninstall

FAQs

--help shows a parameter as Optional. Can I always omit it?

Not necessarily. Some commands have mutually exclusive parameters, meaning you must specify one or the other. Such parameters are individually marked as optional, but at least one of them must be specified. Otherwise, an error is returned. For specific requirement rules, refer to the API documentation of the relevant product.