This topic describes how to use the Alibaba Cloud SDK for Python to call the CreateInstance API of Elastic Compute Service (ECS) to create an ECS instance.

ECS is a basic cloud compute service provided by Alibaba Cloud. ECS is a metered service that you can obtain as easily as utilities such as electricity and water. You do not need to purchase any hardware devices. ECS instances are provisioned based on your business needs. When you no longer need the ECS instances, you can release the resources at any time to save costs.

Before you create an ECS instance, you must obtain the following parameters:

  • Image ID

    Call the DescribeImages API to query the ID of the image that you want to use.

  • Instance type

    Select the instance type that you want to use from the ECS instance family.

Sample code

Notice Run the following sample code to create an ECS instance. You are charged when an instance is created.
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.acs_exception.exceptions import ClientException
from aliyunsdkcore.acs_exception.exceptions import ServerException
from aliyunsdkecs.request.v20140526 import CreateInstanceRequest
# Create an AcsClient object.
client = AcsClient(
# Create a request and set required parameters.
request = CreateInstanceRequest.CreateInstanceRequest()
# Initiate an API request and print the response.
response = client.do_action_with_exception(request)
print response