edit-icon download-icon

Elastic Compute Service

Last Updated: Mar 21, 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. using System;
  2. using Aliyun.Acs.Core;
  3. using Aliyun.Acs.Core.Profile;
  4. using Aliyun.Acs.Core.Exceptions;
  5. using Aliyun.Acs.Ecs.Model.V20140526;
  6. class Sample
  7. {
  8. static void Main(string[] args)
  9. {
  10. // Create a client instance
  11. IClientProfile clientProfile = DefaultProfile.GetProfile("<your-region-id>", "<your-access-key-id>", "<your-access-key-secret>");
  12. DefaultAcsClient client = new DefaultAcsClient(clientProfile);
  13. try
  14. {
  15. // Create a request and set parameters
  16. CreateInstanceRequest request = new CreateInstanceRequest();
  17. request.ImageId = "_32_23c472_20120822172155_aliguest.vhd";
  18. request.InstanceType = "ecs.t1.small";
  19. // Initiate the request and print the handling result
  20. CreateInstanceResponse response = client.GetAcsResponse(request);
  21. Console.WriteLine("InstanceId: {0}", response.InstanceId);
  22. }
  23. catch (ServerException e)
  24. {
  25. Console.WriteLine(e.ErrorCode);
  26. Console.WriteLine(e.ErrorMessage);
  27. }
  28. catch (ClientException e)
  29. {
  30. Console.WriteLine(e.ErrorCode);
  31. Console.WriteLine(e.ErrorMessage);
  32. }
  33. }
  34. }
Thank you! We've received your feedback.