Now that we have a fully setup web server with a domain name, let's dig into the Alibaba Cloud Command Line Interface (CLI) to start managing our cloud resources from the desktop. Later we will begin writing simple python programs to interface with the cloud.
The Alibaba Cloud CLI documentation will be important. Go to the Alibaba Cloud CLI product page.
In the left side menu, expand CLI Python Version, expand Installation
Guide, expand Alibaba Cloud CLI installation guide (Windows), and then
click on Online installation of Alibaba Cloud CLI and SDK.
Here is a Link.
The CLI requires Python version 2.7.x. Check to see if Python is already installed on your system. Open a CMD Prompt. Execute the following command:
If Python is not installed, go to the official Python download server. Download and install Python 2.7.15. Here is Windows 64-bit MSI link. On my system I have both Python 2.7.x and Python 3.x installed. Therefore, I install Python 2.7.x in the C:\Python27 directory.
Change to the C:\Python27 directory:
The CLI requires Python PIP version 7.x or later. The current version (as of May 11, 2018) is
version 10.0.1. Let's double check.
Change to the Python Scripts directory:
Check the PIP version:
My system shows:
To upgrade PIP:
While still in the c:\Python27\Scripts directory, execute the following command:
The CLI does not include the SDKs that are required for each service. This page lists the available SDKs that you can install. Let's start with ECS, OSS and VPC. We will add more later.Execute the following commands while still in the c:\Python27\Scripts directory:
One of the issues with having multiple versions of tools like Python is PATH management. For Windows I write batch scripts to set and unset my Windows search paths. Here are some examples for you to make running the Alibaba CLI and Python scripts easier.To add Python 2.7 to the path, copy the following to a file named set_path.bat (download set_path.zip):
Now when you need to use the CLI, open a CMD Prompt and execute set_path.bat. When finished, either close the CMD Prompt or execute set_oldpath.bat to remove Python from the Windows search path. I have a directory c:\bin in my search path where I copy batch files like to.
The CLI program name is aliyuncli.exe. The CLI takes as its first argument the service that you would like to manage. In the following example we will list the ECS instances.
Let's test the CLI by attempting to list our ECS instances:
This will fail with the following error message. The reason is that we have not given the CLI permissions to access our Alibaba Cloud Account. We will solve this next.
Alibaba Cloud identity and access control service is called Alibaba Cloud Resource Access Management or RAM for short. Here is a link to the RAM product page.
To use the CLI, we need to create an Access Key / Secret Key pair. This key will be installed on our local system. It is very important to protect these keys.Step 1. Go to the Alibaba Resource Access Management Console.
We now have an Access Key and Secret Access Key for the CLI.Step 2. Configure the CLI with the Access Key and Secret.
At the CMD Prompt execute this command:
The CLI will prompt you for several items:
For the first two items, these are the keys that you saved when you create the new user. For the region, either leave it blank or specify your preferred region. I used us-west-1. For the output format, I prefer json.
Let's test the CLI again:
This command will appear to work. There is some output. However, notice that our ECS instance is not displayed. We need to give our user some permissions to access cloud services.
Go back to the RAM console and to the right of the user, click "Authorize". A dialog box will appear that has two columns. The left column displays available policies and the right side shows the policies that are assigned.
In the Search Box, enter the word read. This will limit the displayed policies to the ones containing the word read. Select AliyunECSReadOnlyAccess and click the right arrow button to move the policy to the right side. Now click OK.
Now let's try the CLI again. Now notice how a lot of information is displayed. Rerun the command again and save the output to a file. Open the file in an editor and review the information. Find the InstanceID and Status. We will be using these often.Example ECS commands:
Copyright 2018 NeoPrime LLC