edit-icon download-icon

Auto Scaling

Last Updated: Mar 21, 2018

Auto Scaling is a management service that allows users to automatically adjust elastic computing resources according to their individual needs and policies. For more information about Auto Scaling, see Auto Scaling Documentation.

The examples in this section illustrate how to:

  • Create a scaling group by creating a CreateScalingGroupRequest.

  • Specify I/O-optimized instances by setting the IoOptimized parameter in the scaling group configurations.

Prerequisites

  • Activate the Auto Scaling service and then authorize the RAM user to access the Auto Scaling API.

  • Make sure that you have set up access credentials and service endpoints. For more information, see Set up credentials and Set service endpoints.

Code example: create a scaling group

  1. using System;
  2. using Aliyun.Acs.Core;
  3. using Aliyun.Acs.Core.Profile;
  4. using Aliyun.Acs.Core.Exceptions;
  5. using Aliyun.Acs.Ess.Model.V20140828;
  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 scaling group
  16. CreateScalingGroupRequest csgRequest = new CreateScalingGroupRequest();
  17. csgRequest.MaxSize = 10;
  18. csgRequest.MinSize = 2;
  19. CreateScalingGroupResponse csgResponse = client.GetAcsResponse(csgRequest);
  20. String scalingGroupId = csgResponse.ScalingGroupId;
  21. Console.WriteLine("ScalingGroupId: {0}", scalingGroupId);
  22. // Create scaling configuration
  23. CreateScalingConfigurationRequest cscRequest = new CreateScalingConfigurationRequest();
  24. cscRequest.ScalingGroupId = scalingGroupId;
  25. cscRequest.ImageId = "centos_7_04_64_20G_alibase_201701015.vhd";
  26. cscRequest.InstanceType = "ecs.t1.xsmall";
  27. cscRequest.SecurityGroupId = "G0000000123456789"; // You can obtain the SecurityGroupId through the DescribeSecurityGroups of ECS.
  28. CreateScalingConfigurationResponse cscResponse = client.GetAcsResponse(cscRequest);
  29. Console.WriteLine("ScalingConfigurationId: {0}", cscResponse.ScalingConfigurationId);
  30. }
  31. catch (ServerException e)
  32. {
  33. Console.WriteLine(e.ErrorCode);
  34. Console.WriteLine(e.ErrorMessage);
  35. }
  36. catch (ClientException e)
  37. {
  38. Console.WriteLine(e.ErrorCode);
  39. Console.WriteLine(e.ErrorMessage);
  40. }
  41. }
  42. }

Code example: specify the I/O optimized instance

  1. CreateScalingConfigurationRequest cscRequest = new CreateScalingConfigurationRequest();
  2. cscRequest.ScalingGroupId = scalingGroupId;
  3. cscRequest.ImageId = "centos_7_04_64_20G_alibase_201701015.vhd";
  4. cscRequest.InstanceType = "ecs.t1.xsmall";
  5. cscRequest.IoOptimized = "optimized";
  6. cscRequest.SecurityGroupId = "G0000000123456789";
Thank you! We've received your feedback.