Assistant Engineer
Assistant Engineer
  • UID622
  • Fans3
  • Follows0
  • Posts52

[Free Beta Testing] How To Use the Alibaba Cloud Command Line Tool for ECS

More Posted time:Jul 7, 2016 16:50 PM
[Free Beta Testing] How To Use the Alibaba Cloud Command Line Tool for ECS
In my previous post, I introduced the basic architecture of the Alibaba Cloud Command Line Tool (CLI)
Today, I want to switch to another topic. In the past, we usually performed various operations on the console, such as instance creation, stopping and starting, deleting, and queries. For these operations, the console works quite well. However, for keyboard and Linux enthusiasts, the console does not provide a great experience. Because it lacks the pleasure of actually typing on a keyboard and the excitement of showing off your skills in front of your friends.
In this respect, the Alibaba Cloud CLI is sure to give a little satisfaction to keyboard and Linux aficionados. Today, I will use purely keyboard-based methods to demonstrate how to create, start, stop, and delete instances.
Previously, I told you that the Alibaba Cloud CLI was based on open APIs. Therefore, to create instances, you must call open APIs. First, let us take a look at the necessary parameters:

Below are the required parameters: RegionId, ImageId, InstanceType, and SecurityGroupId.
First, let us suppose that we want to create the most basic instance in the wonderful Qingdao machine room (as this is my demo, naturally I want to use the cheapest possible configuration). Now, how can we do so without any other queries?
1. Query the RegionId:
Use the command below to query the RegionId:
$ aliyuncli Ecs DescribeRegions

Good. Now we can see that the Qingdao RegionId is cn-qingdao.
2. Retrieve all currently available ImageIds.
The ImageId is the image ID you need when starting an image. You can manually select this on the console. Now let's see how to query this image using the CLI:
$ aliyuncli Ecs DescribeImages --outputtable

As there is quite a lot of information, only a portion is shown here. We will select win2012_64_dataCtr_R2_cn_40G_alibase_20150429.vhd as my startup image.

3. Query the InstanceType.
The instance type may change dynamically. When starting an instance, you must query the currently available instance types.
$ aliyuncli Ecs DescribeInstanceTypes --outputtable

Select the type: ecs.t1.small

4. Query all SecurityGroupIds in the Qingdao region.
When starting an instance, you must add it to a specific security group. Security groups are closely related to regions. Therefore, you must specify the RegionId in the query. The Qingdao RegionId is cn-qingdao. Thus:
$ aliyuncli Ecs DescribeSecurityGroups--RegionId cn-qingdao

We can obtain the ID of one security group: sg-28y0uoo07.

5. Everything is ready, so we just need to create the instance.
It is actually very easy to start an instance. The preparation is a bit difficult, but once you have prepared the information, you can start creating the instance:
$ aliyuncli Ecs CreateInstance --RegionIdcn-qingdao –ImageId
--InstanceType ecs.t1.small--SecurityGroupId sg-28y0uoo07

Now we have successfully created the instance.

6. Query this instance.
With the instance ID, we can query the information about the instance and its running status.
$ aliyuncli Ecs DescribeInstanceAttribute--InstanceId i-2818hr0xz

As you can see, the information matches what we have just entered.  
7. Query all instances in the Qingdao region.
Next, we will query the information about all instances in the Qingdao region:
$ aliyuncli Ecs DescribeInstances

Good. We can see two instances. One of these is the instance we have just created.
The status is 'Stopped'.  
8. Start the instance.
$ aliyuncli Ecs StartInstance --InstanceId i-2818hr0xz

Check its status:
$ aliyuncli Ecs DescribeInstanceAttribute--InstanceId i-2818hr0xz
Screenshot omitted.
The instance status will change from Stopped to Starting to Running. This generally takes about 1 minute.
9. Stop the instance.
$ aliyuncli Ecs StopInstance --InstanceId i-2818hr0xz

As before, check the status:
The instance status will change from Running  Stopping  Stopped.
10. Delete the instance.
This is the end of the demo, so we should delete the instance.
$ aliyuncli Ecs DeleteInstance --InstanceIdi-2818hr0xz

Once again, use DescribeInstances to check its status:

Ok, we have now deleted the instance.
In conclusion, these operations may seem silly to keyboard and Linux lovers. After all, the operations are very simple, and you can do the same thing on the console with just a few clicks. However, what if you have 100 or 99 ECS instances? Would you still want to click them one by one? For new users, this tool can serve as your dictionary of open APIs. For users familiar with Alibaba Cloud open APIs, the tool can also be of great help.
The Alibaba Cloud CLI makes it easy to query and call open APIs. After secondary development, the tool can also increase the O&M efficiency. This is also part of my current job.

Latest likes:


  • UID619
  • Fans3
  • Follows2
  • Posts59
1st Reply#
Posted time:Jul 13, 2016 13:22 PM
These steps are very detailed, but I have different ideas for 7.8 steps.
can you send me?
[Blanche edited the post at Jul 13, 2016 17:05 PM]

Assistant Engineer
Assistant Engineer
  • UID621
  • Fans1
  • Follows0
  • Posts55
2nd Reply#
Posted time:Jul 13, 2016 16:57 PM
what is these picture express?  I don't understand.