Running the Yandex Cloud CLI commands
CLI commands are grouped by Yandex Cloud service or component.
Note
To get help information for a particular command, specify the --help global flag.
Commands are executed after authentication, and the token is then saved in the file system. You can also get the token from the YC_IAM_TOKEN environment variable regardless of whether or not you have a saved token.
Providing multiple values for a single parameter
Some CLI parameters can take multiple values. Depending on the command, you can either provide a comma-separated list of values or specify them individually by repeating the parameter:
yc <command> \
--<parameter> <value_1> \
--<parameter> <value_2>
The supported method for providing values depends on the command and parameter. Before running a command, view its description:
yc <command> --help
Examples
When creating a function version, you can provide each environment variable in a separate --environment parameter. For example, this method is useful if the variable value contains commas:
yc serverless function version create \
--function-name my-function \
--runtime python312 \
--entrypoint main.handler \
--source-path ./function.zip \
--environment OPENSEARCH_HOSTS='["hostname1","hostname2","hostname3"]' \
--environment OPENSEARCH_INDEX=index_v2
When assigning roles for a certificate, provide each binding individually by repeating the --access-binding parameter:
yc certificate-manager certificate set-access-bindings my-certificate \
--access-binding role=editor,subject=userAccount:gfei8n54hmfh******** \
--access-binding role=viewer,subject=userAccount:helj89sfj80a******** \
--access-binding role=editor,subject=serviceAccount:ajel6l0jcb9s********
Managing a CLI configuration
Use one of the following to set or change the values of the CLI configuration parameters before executing a command:
-
Profiles: They store the value of a parameter (or multiple parameters) to use when running each command.
You can create multiple profiles and switch between them as you need or run a command once using parameters from another profile by specifying the global
--profileparameter.For more information about profile management, see the step-by-step instructions.
-
Global parameters: They define properties only once when a command is called.
Global parameters are available for any command at any nesting level, but not all commands can process them. For example, if a resource is defined only by an ID, the cloud and folder parameters are ignored.
For a full list of available configuration parameters, see CLI configuration.
Accessing resources by name
In most CLI commands, you can use either the resource ID or resource name. If you access a resource by its name, the search will be limited to the default folder.
If the resource is in a different folder and you want to access it, specify the folder explicitly via a global parameter:
yc <command> <resource_name> --folder-id <folder_ID>
yc <command> <resource_name> --folder-name <folder_name>
# Examples
yc compute instance get testvm --folder-id b1g2doq3bh19********
yc lockbox payload get my-secret --folder-name testname
To find out the default folder:
yc config list
Tip
If using a resource ID, you do not need to specify the folder because their IDs are unique.
Synchronous command execution
Some commands take a long time to execute. In this case, you can control the timing of command execution.
While a command is running, the CLI displays dots in synchronous mode and immediately provides information about the operation in asynchronous mode. For more information about synchronization, see Synchronous and asynchronous modes of command execution.
Connecting to a proxy server
The CLI can send requests to Yandex Cloud through a proxy server. To do this, you need to create the HTTPS_PROXY environment variable which the CLI will read for connection parameters. In the variable, specify:
- Login and a password if authentication is required to connect.
- Proxy server domain name or IP address.
- Port to connect to.
Tip
In the proxy server URL, specify the protocol used by the proxy server for incoming connections. If you do not know the protocol, contact your administrator. For more information about supported protocols, see this net/http package guide
If the password contains special characters, replace them with hexadecimal ASCII codes. For example, if the password contains the @ character, use %40.
To create the HTTPS_PROXY environment variable, run this command:
export HTTPS_PROXY="https://user:password@hostname:port"
To disable traffic routing through the proxy server, clear HTTPS_PROXY:
unset HTTPS_PROXY
To create the HTTPS_PROXY environment variable, run this command:
$Env:HTTPS_PROXY = "https://user:password@hostname:port"
To disable traffic routing through the proxy server, restart the shell or clear HTTPS_PROXY using the command below:
$Env:HTTPS_PROXY = ""
To create the HTTPS_PROXY environment variable, run this command:
set HTTPS_PROXY=https://user:password@hostname:port
To disable traffic routing through the proxy server, restart the shell or clear HTTPS_PROXY using the command below:
set HTTPS_PROXY=
Command versioning
To quickly release new service functionality and provide broader coverage of public API calls, the Yandex Cloud CLI is gradually introducing a new approach to generating command trees directly from the public gRPC API proto specifications
With the new approach in place, new commands and their parameters are not always the same as the previous ones. For backward compatibility, versioning of service command trees has been implemented.
In each group of service commands, e.g., yc compute, the main command branch remains as before: yc compute [ instance | image | disk | ... ], but branches with command version numbers are also added, e.g., yc compute v0 [ instance | image | disk | ... ].
The main branch of commands must match one of the versions. If there is only one version, the main branch completely duplicates it.
The information on adding or removing a command version, as well as on switching the main branch to another version, is published in Yandex Cloud CLI releases.
Tip
Use the current version of the CLI and the command tree the service has assigned as the main one. If CLI commands are called from scripts, CI/CD, or other automated processes, first check command compatibility when migrating to a new CLI version. While the legacy version of the commands is available, you can explicitly state it in specific commands or set it as the default version.
For more information, see Working with Yandex Cloud CLI command versions.
Useful links
Working with the Yandex Cloud CLI and API in Microsoft Windows