This article explains how to retrieve the Image ID in Alibaba Cloud’s virtual server environment, ECS (Elastic Compute Service), using the CLI (Command Line Interface).
When building ECS instances, specifying the appropriate Image ID is essential, and utilizing the CLI allows for quick and efficient retrieval.
Table of Contents
The Alibaba Cloud CLI is a tool for operating various Alibaba Cloud services from the command line.
It is equivalent to AWS CLI provided by Amazon Web Services, allowing resource management and operations to be executed without using a browser.
For detailed information about the Alibaba Cloud CLI, please refer to the official documentation:
〇 Alibaba Cloud Official Documentation
https://www.alibabacloud.com/help/en/cli
The following steps outline how to retrieve the ECS Image ID. In this example, we use WSL (Windows Subsystem for Linux) with Almalinux 8 installed on a Windows 11 PC.
First, use Almalinux 8 on WSL and install the CLI with the following command:
curl -sL https://github.com/aliyun/aliyun-cli/releases/download/v3.0.188/aliyun-cli-linux-3.0.188-amd64.tgz | sudo tar xzC /usr/local/bin
* For detailed information, please refer to the GitHub release page or the official Alibaba Cloud documentation:
〇 GitHub
https://github.com/aliyun/aliyun-cli
https://github.com/aliyun/aliyun-cli/releases
〇 Alibaba Cloud Official Documentation
https://www.alibabacloud.com/help/en/cli/installation-guide
After installation, verify the version with the following command to ensure it is installed correctly:
aliyun version
If version “3.0.188” is displayed, the installation is successful.
To use the CLI, you need to create a RAM user with Administrator privileges.
During creation, the following information will be output; make sure to note it down:
This information will be used in the profile configuration.
Set up the profile with the following command:
aliyun configure --profile default
After execution, input the following information in order:
Once “Configure Done!!!” is displayed, the setup is complete.
If you’re unsure of the command to execute, check the help to see available options:
aliyun --help
This will display a list of available options and resources for the aliyun command.
To specify the “ECS” resource and investigate help for a specific service:
aliyun ecs --help
This will display a list of available APIs.
Among them, “DescribeImages” seems appropriate for retrieving image information. Use it to obtain results in JSON format:
aliyun ecs DescribeImages
The output will be displayed in JSON format, allowing you to check the necessary information.
By the way, even the help for the aliyun ecs DescribeImages command can be checked as follows.
When you actually want to execute something against ECS using the CLI, you should also refer to other parameters like the following.
aliyun ecs DescribeImages help
To make the output more readable, use the –output option to extract specific fields:
By using this option and specifying the following three “Fields,” you can extract only the parts you are looking for.
cols | This refers to the names of the rows that exist in the fields. For example, in the output of aliyun ecs DescribeImages, ImageId, OSNameEn, and Status are applicable. |
rows | Use JMESPath to specify the path where the field you want to filter exists. For example, in the output of aliyun ecs DescribeImages, Images and Image are applicable. |
num | This outputs row numbers starting from 0 on the left side of the result. However, by default, it is not displayed. |
Taking this into account, the following command extracts and displays only the specific fields.
If you add num=true at the end, the row numbers will be displayed on the left side.
aliyun ecs DescribeImages --PageSize 100 --output cols="ImageId,OSNameEn,Status" rows="Images.Image[]" aliyun ecs DescribeImages --PageSize 100 --output cols="ImageId,OSNameEn,Status" rows="Images.Image[]" num=true
This command will display the Image ID, OS name, and status in a tabular format.
By using the Alibaba Cloud CLI, you can quickly and efficiently retrieve the ECS Image ID, facilitating smoother resource management and operations.
* For detailed information and the latest updates, please refer to the official documentation:
〇 Alibaba Cloud Official Documentation
https://www.alibabacloud.com/help/en/cli/installation-guide
● Website development, server construction — service consultation ●
▼ Company WeChat Official Account▼
▼ Contact person in charge WeChat ID ▼
Follow us on WeChat
WeChat Official Account
Person in ChargeWeChat