edit-icon download-icon

Elastic Compute Service

Last Updated: Mar 20, 2018

Elastic Compute Service (ECS) is a type of computing service that features elastic processing capabilities. ECS has a simpler and more efficient management mode than physical servers. You can create instances, change the operating system, and add or release any quantity of ECS instances at any time to fit your business needs. For more information about ECS, see Elastic Compute Service Documentation.

Example overview

The example in this section shows you how to create an ECS instance by creating a CreateInstanceRequest. To create an ECS instance, obtain the following information:

Code example

Note: Running the code in this example will create an ECS instance and generate fees.

  1. from aliyunsdkcore.client import AcsClient
  2. from aliyunsdkcore.acs_exception.exceptions import ClientException
  3. from aliyunsdkcore.acs_exception.exceptions import ServerException
  4. from aliyunsdkecs.request.v20140526 import CreateInstanceRequest
  5. # Create the DefaultAcsClient instance
  6. client = AcsClient(
  7. "<your-access-key-id>",
  8. "<your-access-key-secret>",
  9. "<your-region-id>"
  10. );
  11. # Create a request and set parameters
  12. request = CreateInstanceRequest.CreateInstanceRequest()
  13. request.set_ImageId("alinux_17_01_64_20G_cloudinit_20171222.vhd")
  14. request.set_InstanceName("MyInstance")
  15. request.set_SecurityGroupId("<your-security-group-id>")
  16. request.set_InstanceType("ecs.t1.small")
  17. request.set_ClientToken("<uuid>")
  18. # Initiate the request and print the response
  19. response = client.do_action_with_exception(request)
  20. print response
Thank you! We've received your feedback.