All Products
Search
Document Center

Simple Log Service:Configure SLS CLI

Last Updated:Jun 08, 2026

Configure SLS CLI to set default credentials, endpoint, and output format for all commands.

Credential sources and priority

SLS CLI reuses Alibaba Cloud CLI credentials when available—no additional account setup is needed. Configure Alibaba Cloud CLI.

Credential resolution priority (highest to lowest):

Credential source

Description

Subcommand parameters (AccessKey pair, region)

Credentials passed directly in the subcommand.

The profile parameter in SLS CLI

Uses the profile specified by --profile=Name of a credential configuration in the config.json file of Alibaba Cloud CLI. For more information about the --profile parameter, see Global parameters.

ALIYUN_LOG_CLI environment variable

Uses the ALIYUN_LOG_CLI environment variable.

SLS CLI configuration file

Named .aliyunlogcli. For more information, see Configure the default account and Configure multiple accounts.

ALIBABACLOUD environment variable (Alibaba Cloud CLI)

Uses the ALIBABACLOUD environment variable.

ALICLOUD environment variable (Alibaba Cloud CLI)

Uses the ALICLOUD environment variable.

Alibaba Cloud CLI configuration file

Uses the Alibaba Cloud CLI configuration file.

Note

Configuration file paths:

  • Linux: ~/.aliyun/config.json

  • Windows: C:\Users\UserName\.aliyun\config.json

Configure the default account

SLS CLI uses the main account by default. Configure an AccessKey pair and endpoint for the main account and grant it permissions to manage projects.

  1. Log on to the SLS CLI server.

  2. Configure the default account credentials.

    Run the following command:

    aliyunlog configure "AccessKey ID" "AccessKey Secret" Endpoint
  3. Verify the configuration.

    Open the .aliyunlogcli configuration file. If it contains output similar to the following, the default account is configured.

    [main]
    access-id = LTAI******pLMZ
    access-key = XjAsP******eRqax
    region-endpoint = cn-hangzhou.log.aliyuncs.com
    sts-token =
    Note

    The .aliyunlogcli file path by operating system:

    • Linux: ~/.aliyunlogcli

    • Windows: C:\Users\UserName\.aliyunlogcli

    If configuration fails, fix the error based on the returned error code.

Configure multiple accounts

To manage log data across accounts, configure credentials and endpoints for each account.

  1. Log on to the SLS CLI server.

  2. Configure credentials for additional accounts.

    Run the following command:

    aliyunlog configure "AccessKey ID" "AccessKey Secret" Endpoint Name
    • Replace Name with a custom account name.

  3. Verify the configuration.

    Open the ~/.aliyunlogcli configuration file. If it contains output similar to the following, the accounts are configured.

    [main]
    access-id = LTAI******pLMZ
    access-key = XjAsP******eRqax
    region-endpoint = cn-hangzhou.log.aliyuncs.com
    sts-token =
    
    [test]
    access-id = As******sPzvb
    access-key = FtagJeR******bQqax
    region-endpoint = cn-shanghai.log.aliyuncs.com
    sts-token =
    Note

    The .aliyunlogcli file path by operating system:

    • Linux: ~/.aliyunlogcli

    • Windows: C:\Users\UserName\.aliyunlogcli

    If configuration fails, fix the error based on the returned error code.

    Use --client-name=testName to run a command with a specific account. For example, aliyunlog log create_project ..... --client-name=test runs the command as the test account.

Format output

SLS CLI supports JSON formatting and character escaping for output.

  • Format JSON output

    By default, SLS CLI outputs JSON in a single line. Format the output using one of these methods:

    • Format the output of a specific command

      Example: aliyunlog log get_log .... --format-output=json formats the JSON output of the get_log command.

    • Format the output of all commands

      Run aliyunlog configure --format-output=json to format all command output globally.

  • Escape characters

    By default, non-English characters in output are escaped. To return original characters, set --format-output to no_escape.

    Run aliyunlog configure --format-output=no_escape to disable escaping globally.

Escape special characters

Queries containing dollar signs ($), grave accents (`), backslashes (\), or exclamation points (!) may fail or return incorrect results.

Escape these characters with backslashes (\) or single quotes ('):

  • Escape special characters with backslashes (\):

    aliyunlog log get_log_all --project="my-project" --logstore="my-logstore" --query="event_name:\$_enter" --from_time="2021-06-24 15:00:00+08:00" --to_time="2021-06-24 16:00:00+08:00"

  • Enclose the query in single quotes ('):

    aliyunlog log get_log_all --project="my-project" --logstore="my-logstore" --query='event_name:$_enter' --from_time="2021-06-24 15:00:00+08:00" --to_time="2021-06-24 16:00:00+08:00"

The Bash Quoting manual covers additional escaping rules.