[Osaka/Yokohama/Tokushima] Looking for infrastructure/server side engineers!

[Osaka/Yokohama/Tokushima] Looking for infrastructure/server side engineers!

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Successor to CentOS] AlmaLinux OS server construction/migration service

[Successor to CentOS] AlmaLinux OS server construction/migration service

[For WordPress only] Cloud server “Web Speed”

[For WordPress only] Cloud server “Web Speed”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Reservation system development] EDISONE customization development service

[Reservation system development] EDISONE customization development service

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[Global exclusive service] Beyond's MSP in North America and China

[Global exclusive service] Beyond's MSP in North America and China

[YouTube] Beyond official channel “Biyomaru Channel”

[YouTube] Beyond official channel “Biyomaru Channel”

Get ECS image ID with Alibaba Cloud CLI

Introduction

I'm Takagi from the Technical Sales Department, and I still get lost for about 10 minutes at the beginning.

So this time, I'm going to use the "Alibaba Cloud CLI" to get the image ID of Alibaba Cloud's virtual server environment "ECS (Elastic Compute Service)"!

When you want to build ECS using Terraform, it is absolutely necessary to specify this "image ID", but it seems that it is faster to obtain it using this "Alibaba Cloud CLI", so this time I will do it as a memorandum. I'll keep it.

*I will also write an article about Terraform properly someday. .

What is Alibaba Cloud CLI?

First, I would like to briefly explain this "Alibaba Cloud CLI", but if you are a regular user of AWS, I think there will be no problem in interpreting it as the Alibaba Cloud version of the "AWS CLI". Masu.

This tool is used to manage resources with the CLI rather than the browser, but just in case we have included a link to the official documentation

By the way, the Japanese version is currently being prepared (as of the publication of this article on January 18, 2024) , so I read it using a translation tool.

General flow

The flow is as follows, and this time we will use WSL (Almalinux 8) installed on a Windows 11 PC.

  1. Install/unzip with curl command
  2. Operation confirmation
  3. Create RAM user and get API key
  4. Creating a profile
  5. Get image ID
  6. Retrieving information using --output
  7. summary

Install/unzip with curl command

Open WSL and start Almalinux, then install and unzip it using the commands below.

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

By the way, detailed information is also available on Github, so please check that as well.

■ Github

https://github.com/aliyun/aliyun-cli

https://github.com/aliyun/aliyun-cli/releases

■ Official manual

https://www.alibabacloud.com/help/zh/alibaba-cloud-cli/latest/installation-guide?spm=a2c63.p38356.0.0.106b6d42SZzhML

Operation confirmation

Run the command below to check the version of Alibaba Cloud CLI you have installed.

aliyun version

This time, "3.0.188" should be displayed, and if you can confirm this, it's OK!

RAM user creation

However, as it is, you will still not be able to obtain the necessary information via CLI, so first create a user with Administrator privileges.

Also, please note the following three pieces of information that will be output at that time.

  1. AccessKey ID
  2. AccessKey Secret
  3. Default Region ID

*You can also obtain it in CSV when creating a user!

Creating a profile

Once you have noted down the above three points, open Almalinux8 in WSL and execute the command below.

aliyun configure --profile default

Then, as shown in Figure 1 below, you will be asked for the information mentioned earlier in an interactive format, so enter it one by one.

■ Figure 1

■ Input order

  1. AccessKey ID → Enter personal information
  2. AccessKey Secret → Enter personal information
  3. Default Region ID → ap-northeast-1
  4. Default Language → en

At the end, if "Configure Done!!!" appears, you are done.

Get image ID

However, as it is, I don't know what command to actually execute, so I'll check help to see what options are available!

■ Execution command

aliyun --help

■ Execution result

Since it's long, I've excerpted some of it, but you can display a list of options and resources that can be used with the aliyun command, so you can specify the "ECS" resource that is our requirement, and then get help for a specific service. I'll investigate.

■ Execution command

aliyun ecs --help

■ Execution result

A list of available APIs will be displayed. Use "DescribeImages", which seems most applicable, to get the results in JSON format.

■ Execution command

aliyun ecs DescribeImages

■ Execution result

I've excerpted some of it because it's long, but the result in JSON format will be output like this. You can see that the information you wanted to know this time can be obtained from the "ImageId" part!

Personally, I think it's good to combine grep and ``extract only the parts you want'', but this time I'll use ``--output'', which is nicely summarized in the official documentation I will do it!

As a side note, you can also check the help for the "aliyun ecs DescribeImages" command as shown below, so if you actually want to do something with ECS from the CLI, you also check the help for the "aliyun ecs DescribeImages" command. Please use it as a reference !

■ Execution command

aliyun ecs DescribeImages help

■ Execution result

Retrieving information using --output

Alibaba Cloud CLI provides the "-- output" option to make the output results of the above command more intuitive and easy to understand. By specifying this option and the following three "Fields", you can , you can extract only the parts that interest you.

■ Field

cols

The name of the row that exists in the field.

For example, using the results of "aliyun ecs DescribeImages"

This includes "ImageId", "OSNameEn", and "Status".

rows

Use JAMESPATH the path where the field you want to filter exists

For example, "Images" and "Image" are the results of "aliyun ecs DescribeImages".

num

It will output the number of rows starting from 0 on the left side of the result. The default is no output.

Based on the above, the command executed is as follows.

If you put "num=true" at the end of this, the number of rows will be output on the left side.

■ Execution command

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

■ Execution result

The "rows" part needs to be specified using JAMESPATH

This is a relief!

summary

What did you think?

Personally, it took me a while to read the documentation for the JAMESPATH part, so I had a little trouble with it, but now I can build resources with Terraform with confidence!

Lastly, we have opened an office in Shenzhen, and we support our customers' systems from design and construction to operation and maintenance through the services of various cloud vendors, including Chinese clouds such as Alibaba Cloud and Tencent Cloud. It is possible to do so.

In addition to reading this article, we hope that you will also be interested in Beyou Technology (Shenzhen) Co., Ltd.

I will continue to write mainly articles related to AlibabaCloud, so please check it out!

If you found this article helpful , please give it a like!
5
Loading...
5 votes, average: 1.00 / 15
244
X facebook Hatena Bookmark pocket
[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

[Osaka/Yokohama] Actively recruiting infrastructure engineers and server side engineers!

[Osaka/Yokohama] Actively recruiting infrastructure engineers and server side engineers!

The person who wrote this article

About the author

Masahiro Takajo

After graduating from university, I joined a certain system integrator and
started my career as an infrastructure engineer.
He joined Beyond in June 2021 and
currently belongs to the System Solutions Department.
We provide 24-hour, 365-day operation, maintenance, and monitoring services for servers and clouds used by companies that primarily provide web-based services.

The qualifications held are as follows:
① AWS SAA
② Lpic 101