This topic describes how to install and use the Alibaba Cloud CLI extension for Visual Studio Code (VS Code). In this example, the DescribeInstances
operation of Elastic Compute Service is called by using the Alibaba Cloud CLI extension in the VS Code editor.
Prerequisites
Alibaba Cloud CLI is installed, and the profile information is configured for Alibaba Cloud CLI. For more information about how to install Alibaba Cloud CLI and configure the profile information, see Use Alibaba Cloud CLI to call API operations.
The
AliyunECSReadOnlyAccess
permission is granted to the Resource Access Management (RAM) user that you use to access Alibaba Cloud CLI.ECS
Overview
To use the Alibaba Cloud CLI extension to call the DescribeInstances
operation of ECS in the VS Code editor, perform the following steps:
Install the Alibaba Cloud CLI extension, which is named
Alibaba Cloud CLI Tools
.Create a file with the file name extension
.aliyun
and write the command for calling theDescribeInstances
operation in the file.Select the command that you want to run and run the command in the editor or on the terminal.
Step 1: Install the Alibaba Cloud CLI extension
Install the extension from the marketplace
In the left-side activity bar of the VS Code editor, click the icon.
Enter
Alibaba Cloud CLI Tools
in the search box. Select Alibaba Cloud CLI Tools from the search results and click Install.
Install the extension from a browser
Visit the official page of Alibaba Cloud CLI Tools in the marketplace in a browser and click Install. You are navigated to the Alibaba Cloud CLI extension page in the VS Code editor.
Click Install.
After the Alibaba Cloud CLI extension is installed, the icon and current configuration of the Alibaba Cloud CLI extension are displayed in the bottom status bar. You can click the icon to configure the profile information for the extension.
Step 2: Write a command
In the VS Code editor, choose File > New File. In the dialog box that appears, enter
example.aliyun
to create a file with the file name extension.aliyun
.NoteWhen you write code in the
.aliyun
file, the Alibaba Cloud CLI extension provides command completion hints. This greatly improves your coding efficiency.Auto completion for commands
Auto completion for methods
Auto completion for parameters
Write the following command based on the hints and specify the parameters as needed.
aliyun ecs DescribeInstances --InstanceIds "['i-bp118piqciobxjkb****']"
Step 3: Run the command
After a command is written, you can run the command on the terminal or in the editor.
Run the complete command on the terminal
Click run above the command that you want to run to open the terminal and run the complete command.
Run the selected part of the command on the terminal
Press and hold the left mouse button to select the part of the command that you want to run. Right-click the selected part.
Choose Alibaba Cloud CLI > Run Line in Terminal to open the terminal and run the selected part of the command.
Run the selected part of the command in the editor
Press and hold the left mouse button to select the part of the command that you want to run. Right-click the selected part.
Choose Alibaba Cloud CLI > Run Line in Editor to run the selected part in the VS Code editor.