edit-icon download-icon

Configure CLI for Apsara Stack and Private Region

Last Updated: Jan 16, 2018

Note: This file is for Apsara Stack and Private Region users to configure their Alibaba Cloud CLI. If you are a Public Cloud user, see Configure Alibaba Cloud CLI (for Public Cloud).

After installing Alibaba Cloud CLI, you must configure the security certificate before you can use Alibaba Cloud CLI to manage your Alibaba Cloud products. Every request you send must contain the certificate information. Therefore, you must create an AccessKey on a device connected to the Internet.

In addition to the security certificate, you can also set up your RegionId of Apsara Stack or Private Region, and the default output format of Alibaba Cloud CLI, such as text, table, or JSON.

To configure Alibaba Cloud CLI, follow these steps:

  1. Create an AccessKey.

  2. Add the RegionId for Apsara Stack or Private Region.

  3. Configure Alibaba Cloud CLI.

Create AccessKey

Apsara Stack or Private Region users must apply for two accounts: User ID (UID) and Business ID (BID). Both UID and BID have their own AccessKeyId and AccessKeySecret. UID is used to manage Alibaba Cloud assets. BID is used to execute expense-related operations, such as creating, removing, and modifying the settings of Alibaba Cloud assets. You cannot use your BID to manage your Alibaba Cloud assets. Therefore, consider which operations you want to perform to determine which AccessKeyId and AccessKeySecret you require to configure Alibaba Cloud CLI.

The following examples are commands for a UID:

  1. aliyuncli ecs StartInstance --InstanceId i-3XXXXkts
  1. aliyuncli ecs RebootInstance --InstanceId i-37XXXXX

The following example is a command for a BID:

  1. aliyuncli ecs DeleteInstance --InstanceId iXXXXXXk3 --OwnerAccount zXXXXXXXXXer@aliyun.com

Create UID and its AccessKey

  1. Run the following command to download and install the SDK of AAS.

    1. $ sudo pip install aliyun-python-sdk-aas
  2. Run the following command to create your UID/AliyunId and PK code.

    1. aliyuncli aas CreateAliyunAccount

    Once the UID and PK code have been created, the system displays information as the follows:

    Create UID access key

  3. Run the following command to create your AccessKeyId and AccessKeySecret.

    1. aliyuncli aas CreateAccessKeyForAccount --PK XXXXXXX

    Once the AccessKeyId and AccessKeySecret have been created, the system displays information as the follows:

    Create UID akID

Create BID and its AccessKey

  1. Create an Alibaba Public Cloud UID.

  2. Submit the UID you created to an Alibaba Cloud business manager who then creates your BID.

  3. Use the BID to log on to the Alibaba Cloud console.

  4. Move the mouse to your account name, and click AccessKeys to view your BID’s AccessKeyId and AccessKeySecret.

    Note: If the following prompt appears, click Continue to manage AccessKey.

    AK Security Tips

Add the RegionId for Apsara Stack or Private Region

The RegionId for Apsara Stack or Private Region is likely different from the default RegionId for the Internet. Before configuring Alibaba Cloud CLI, Apsara Stack and Private Region users must add their RegionId to the ‘endpoints.xml’ file of Alibaba Cloud CLI. Further, Apsara Stack users also modify the information of their endpoints.

You instantly get the RegionId for Apsara Stack or Private Region when you purchase them. Current RegionIds supported by the Internet are shown in the table:

Region RegionId
Asia Pacific (Singapore) ap-southeast-1
Shenzhen cn-shenzhen
Qingdao cn-qingdao
Beijing cn-beijing
Shanghai cn-shanghai
US East (Virginia) us-east-1
Hongkong cn-hongkong
Hangzhou cn-hangzhou
US West (Silicon Valley) us-west-1

You can use the following command to query the latest RegionId.

  1. aliyuncli ecs DescribeRegions --output json

Note: If you use an account for the Internet, this query returns the supported RegionId. Under a Apsara Stack or Private Region account, this query returns the RegionId supported by the Apsara Stack or Private Region you have purchased.

Add the Apsara Stack RegionId and modify the endpoint information

By default, Alibaba Cloud’s command line tool does not include an Apsara Stack user’s RegionId and endpoint information, both of which are written in the SDK. If you are a Apsara Stack user, you have two methods to add the RegionId of your Private Region and modify the endpoint information.

Method 1: directly add your RegionId to the file ‘endpoints.xml’ and modify the endpoint information.

Find the file ‘endpoints.xml’ under the SDK Aliyunsdkcore and then the RegionIds.

In a Windows system, the file is located at: C:\Python27\Lib\site-packages\aliyunsdkcore.

In a Linux system, the file is located at: /usr/local/lib/python2.7/site-packages/aliyunsdkcore.

Add your RegionId in the following format.

  1. <RegionIds>
  2. <RegionId>cn-beijing</RegionId>
  3. <RegionId>cn-qingdao</RegionId>
  4. <RegionId>cn-hangzhou</RegionId>
  5. <RegionId>cn-hongkong</RegionId>
  6. <RegionId>cn-shanghai-et2-b01</RegionId>
  7. <RegionId>cn-shanghai</RegionId>
  8. <RegionId>us-west-1</RegionId>
  9. <RegionId>cn-shanghai-et2-test01</RegionId>
  10. <RegionId>cn-shenzhen</RegionId>
  11. <RegionId>ap-southeast-1</RegionId>
  12. </RegionIds>

To modify the endpoint information, change value of DomainName to yours. You can contact a Apsara Stack product manager for this information. An example of modifying the endpoint of ECS is given here to show the modification procedures.

  1. <Product>
  2. <ProductName>Ecs</ProductName>
  3. <DomainName>ecs.aliyuncs.com</DomainName>
  4. </Product>

Method 2: use Alibaba Cloud CLI to add the RegionId and modify the endpoint information.

Only Alibaba Cloud CLI of version v1.0.7 or later can be used to add the RegionId and modify the endpoint information. An Apsara Stack user must set both the RegionId and endpoint. Omission of either of them leads to a failed modification attempt.

In a Windows system, run the following command to set up the name and endpoint of your Private Region.

  1. aliyuncli ecs ModifyEndPoint --RegionId my-region-id --EndPoint my.ecs.domainname.com

In a Linux/UNIX or Mac OS system, run the following command to set up the name and endpoint of your Private Region.

  1. sudo aliyuncli ecs ModifyEndPoint --RegionId my-region-id --EndPoint my.ecs.domainname.com

Note: This command is not directly displayed in Online Help. Incorrectly executing this command makes Alibaba Cloud CLI unusable. Therefore, you must be fully aware of the effects of this command before using it.

Add the RegionId for your Private Region

By default, Alibaba Cloud CLI does not include a Private Region user’s RegionId, which is written in the SDK. If you are a Private Region user, you can use two methods to add your Private Region name.

Method 1: directly add your RegionId to the file ‘endpoints.xml’.

Find the file ‘endpoints.xml’ under the SDK Aliyunsdkcore and then the RegionIds.

In a Windows system, the file is located at: C:\Python27\Lib\site-packages\aliyunsdkcore.

In a Linux system, the file is located at: /usr/local/lib/python2.7/site-packages/aliyunsdkcore.

Add your RegionId in the following format.

  1. <RegionIds>
  2. <RegionId>cn-beijing</RegionId>
  3. <RegionId>cn-qingdao</RegionId>
  4. <RegionId>cn-hangzhou</RegionId>
  5. <RegionId>cn-hongkong</RegionId>
  6. <RegionId>cn-shanghai</RegionId>
  7. <RegionId>us-west-1</RegionId>
  8. <RegionId>cn-shanghai-et2-test01</RegionId>
  9. <RegionId>cn-shenzhen</RegionId>
  10. <RegionId>ap-southeast-1</RegionId>
  11. </RegionIds>

Method 2: use Alibaba Cloud CLI to add the RegionId.

Only Alibaba Cloud CLI of version v1.0.7 or later can be used to add the RegionId. If you are a Private Region user, do not make any modification to --EndPoint ecs.aliyuncs.com.

In a Windows system, run the following command to add a Private Region name.

  1. aliyuncli ecs ModifyEndPoint --RegionId my-region-id --EndPoint ecs.aliyuncs.com

In a Linux/UNIX or Mac OS system, run the following command to add the Private Region name.

  1. sudo aliyuncli ecs ModifyEndPoint --RegionId my-region-id --EndPoint ecs.aliyuncs.com

Note: This command is not directly displayed in Online Help. Incorrectly executing this command makes Alibaba Cloud CLI unusable. Therefore, you must be fully aware of the effects of this command before using it.

Configure parameters of Alibaba Cloud CLI

In a Windows system, run the following command, and enter values for the parameters listed below.

  1. cd C:\Python27
  2. aliyuncli configure
  3. Aliyun Access Key ID [None]: <Enter Access Key ID>
  4. Aliyun Access Key Secret [None]: <Enter Access Key Secret>
  5. Default Region Id [None]: <Enter the Region Id of the instance>
  6. Default output format [None]: <Enter required output format >

In a Linux/UNIX or Mac OS system, run the following command, and enter values for the parameters listed below.

  1. $ sudo aliyuncli configure
  2. Aliyun Access Key ID [None]: <Enter Access Key ID>
  3. Aliyun Access Key Secret [None]: <Enter Access Key Secret>
  4. Default Region Id [None]: <Enter the Region Id of your VPC or Private Region>
  5. Default output format [None]: <Enter required output format>

Modify parameters of Alibaba Cloud CLI

To modify the parameters of Alibaba Cloud CLI, run aliyuncli configure. For each parameter that is not to be modified, press Enter; for each parameter that is to be modified, enter a new value. See the following examples.

In a Windows system, run the following command:

  1. cd C:\Python27
  2. aliyuncli configure
  3. Aliyun Access Key ID [************jkf]: <Enter>
  4. Aliyun Access Key Secret [***************Okl]: <Enter>
  5. Default Region Id [cn-qingdao]: cn-hangzhou
  6. Default output format [table]: <Enter>

In a Linux/UNIX or Mac OS system, run the following command:

  1. $ sudo aliyuncli configure
  2. Aliyun Access Key ID [************jkf]: <Enter>
  3. Aliyun Access Key Secret [***************Okl]: <Enter>
  4. Default Region Id [cn-qingdao]: cn-hangzhou
  5. Default output format [table]: <Enter>
Thank you! We've received your feedback.