Roaming ECS ​​API

Source: Internet
Author: User
Keywords Cloud Computing ECS API
Tags .mall access accounts address aliyun api bandwidth basic

The ECS API has undergone a major update on April 3. In addition to the original basic management functions such as instance management and security group management, this time it opens up the following functions:

  1. Create a Pay Per Click Cloud Server Instance
  2. Create resources such as disks, snapshots, and images
  3. Access to the RAM resource authorization service to support the resource authorization between the accounts


Next, we started roaming to experience the new capabilities of the ECS API, completing the following three tasks:

  1. Configuration Environment
  2. Create an instance
  3. Create a snapshot and customize the image

First, the configuration environment

We use a simple python script to experience the power of ECS, you do not need to know how to write python code, as long as the completion of four simple preparation tasks:

  1. Installed python environment, you need python 2.7 version
  2. Download ecs.py this small script, through a simple command line operation, to call the ECS API
  3. Get your Aliyun account's accesskeyid / accesskeysecret key pair
  4. Download the ECS API documentation

The first step, please install python 2.7 version. Windows / Linux / MacOS and other operating systems how to install This article will not be described.

The second step, from here the link https://aliyunecs.oss.aliyuncs.com/tools/ecs.py download address Download ecs.py script, open the command-line tool to execute the command in windows under linux and mac Use the terminal to execute. Next, we use linux as an example, in the terminal implementation

$ chmod +x ./ecs.py
Plus the implementation of the authority to use more convenient.

The third step, visit http://i.aliyun.com/access_key, click "Create AccessKey" to create an accesskeyid / accesskeysecret key pair. Please save this key pair, this is very important and sensitive information, must not leak.

Next, directly in the terminal ecs.py this script, you can see the help information, we first need to get the key pair has been configured. Use the following command to configure:

$./ecs.py config --id=<access key id> --secret=<access key secret>
After the configuration is complete, you can verify that the configuration is successful by listing the available Region commands:

$./ecs.py DescribeRegions

If there is no problem with the configured key pair, this command will output the result of a json format, which contains the information of two regions: Hangzhou (cn-hangzhou) and Qingdao (cn-qingdao).

The fourth step is to download the ECS API documentation at http://help.aliyun.com/list/11113464.html for future reference.

Second, create an instance

Preconditions: To create a pay-as-you-go cloud server, your account balance must be at least $ 100 in cash. Next we complete the following tasks:

  1. Create a security group
  2. Create a cloud server instance
  3. Assign public IP address
  4. Add a disk
  5. Start the newly created instance

1. Create a security group

Each instance of an ECS belongs to at least one security group, a so-called security group, consisting of instances in the same territory that share the same security requirements and trust each other. Instances that join the same security group trust each other, and the firewall rules of the security group are in force for them.

$ ./ecs.py CreateSecurityGroup description="Test-API" regionid=cn-qingdao

If there is no error, the output is similar to the following, is the successful implementation.

{

"RequestId": "7472C411-08E9-41C7-A20B-BA33E2AA5E7B",

"SecurityGroupId": "G69d5027e-85e4-45cb-a6a5-c1a4de77fab8"

}

Create an instance

Before creating an instance, there are several options to do: 1) to create a geographical area? 2) What configuration to choose 3) Which mirror to use? 4) Which security group to join? 5) Need public network bandwidth? Use fixed bandwidth or pay by traffic? 6) Set Root password

This API can only be used to create a cloud server instance that is paid-for-service. For some restrictions, you can see specific information at http://help.aliyun.com/view/11108189_13545434.html.

We will create a ecs.s2.small (2CPU 2GB memory) cloud server instance in Qingdao area. Select ubuntu12.04 operating system, add to the security group just created, and choose to pay by traffic, and allow 10Mbps public network bandwidth. The order is as follows:

$./ecs.py CreateInstance RegionId=cn-qingdao

InstanceType=ecs.s2.small

ImageId=ubuntu1204_64_20G_security_v01.vhd

InternetChargeType=PayByTraffic

InternetMaxBandwidthOut=10

SecurityGroupId=刚刚创建的安全组ID

InstanceName=api-test

Password=your-password

Command execution, if there is no error, there will be similar to the following json output, on behalf of the successful implementation:

{

"InstanceId": "AY140404124925248f45",

"RequestId": "024E0224-8B12-4099-897E-F717CF43332C",

}

At this point, the instance has been created successfully, want to see its properties, the implementation

$./ecs.py DescribeInstanceAttribute InstanceId=刚创建成功的实例ID

Can see its Status is Stopped state, we need some configuration to start the instance.

3. Assign public IP address

We just created a good example does not contain the IP address, you want to increase the public IP address, execute the command:

$./ecs.py AllocatePublicIpAddress InstanceId=刚创建成功的实例ID

The following output is successful

{

"IpAddress": "42.96.194.117",

"RequestId": "46C20C19-93E8-4CCE-853C-5F26241A7EDA"

}

4. Add a data disk

Just created cloud server is no data disk, we call AddDisk this command to add a 100GB data disk:

$./ecs.py AddDisk InstanceId=刚创建成功的实例ID Size=100

{

"DiskId": "6002-20107932",

"RequestId": "5E859722-D05A-4FE2-B7B1-F1F20FA10C12"

}

5. Start the instance

This time, we can start the instance, execute:

$./ecs.py StartInstance InstanceId=刚刚创建成功的实例ID

{

"RequestId": "09F57060-739C-409F-9907-78FECEC33E46"

}

No news is good news, this time, then call DescribeInstanceAttribute you can see the instance Status is Starting, a few minutes later, the instance will start well, you can SSH remote connection or through the console connection management terminal.

Third, create a snapshot and custom mirror

A snapshot is a copy of the data on a disk at some point in time. Custom Mirroring is an example of a runtime environment template that can be selected, typically including the operating system and pre-installed software. Only the system tray snapshot can be made into a custom image.

First use the DescribeInstnaceDisks API to view the system disk ID:

$./ecs.py DescribeInstanceDisks InstanceId=刚创建成功的实例ID

If you follow the steps in Step 2, there should be two disks in the output, where Type identifies System as the system disk.

Create a snapshot of the system disk with the following command:

$./ecs.py CreateSnapshot InstanceId=刚创建成功的实例ID DiskId=系统盘的ID SnapshotName=my-sys-snapshot

SnapshotID will be output after successful creation. Snapshot generation process takes some time, you can view the progress of the snapshot by the following command:

$./ecs.py DescribeSnapshotAttribute RegionId=cn-qingdao SnapshotId=刚刚创建的SnapshotId

{

"CreationTime": "2014-04-04T05:39Z",

"Progress": "73",

"RequestId": "783D64E0-5193-433A-9615-26390783DE68",

"SnapshotId": "6002-20107931-4969987",

"SnapshotName": "my-sys-snapshot"

}

Progress is the percentage of progress.

When Progress reaches 100, you can use this snapshot to create a custom image. Use the following command to create a custom image:

$./ecs.py CreateImage RegionId=cn-qingdao SnapshotId=创建成功的SnapshotId Description=my-image

{

"ImageId": "md5079e28-3b58-48eb-af0a-3da8dcbe56be.vhd",

"RequestId": "F7E07872-2859-4D50-A223-FEE748DBCFB4"

}

At this point, this new ImageId can be used to create a new instance.

This is the end of our roaming. You can go a step further and control the API documentation to accomplish the following tasks:

  1. See all available images: DescribeImages
  2. Lists Security Groups (DescribeSecurityGroups) and adds a AuthorizeSecurityGroups to the security group that allows only the public network's 22 and 80 ports to access instances
  3. Try snapshots and other disk features

If you want to write code to call the ECS API, then the contents of this link can help you simplify the signature encryption http://dev.aliyun.com/read.php?tid=42, you can find Java / PHP / C # / Python sample code.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.