edit-icon download-icon

Auto Scaling

Last Updated: Mar 20, 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. #include <iostream>
  2. #include <alibabacloud/core/AlibabaCloud.h>
  3. #include <alibabacloud/ess/EssClient.h>
  4. using namespace AlibabaCloud;
  5. using namespace AlibabaCloud::Ess;
  6. int main(int argc, char** argv)
  7. {
  8. // Initialize the SDK
  9. AlibabaCloud::InitializeSdk();
  10. // Create a client instance
  11. ClientConfiguration configuration("<your-region-id>");
  12. EssClient client("<your-access-key-id>", "<your-access-key-secret>", configuration);
  13. // Create a scaling group
  14. Model::CreateScalingGroupRequest csgRequest;
  15. csgRequest.setMaxSize(10);
  16. csgRequest.setMinSize(2);
  17. auto csgOutcome = client.createScalingGroup(csgRequest);
  18. if (csgOutcome.isSuccess())
  19. {
  20. std::string scalingGroupId = csgOutcome.result().getScalingGroupId();
  21. std::cout << "ScalingGroupId: " << scalingGroupId << std::endl;
  22. // Create scaling configuration
  23. Model::CreateScalingConfigurationRequest cscRequest;
  24. cscRequest.setScalingGroupId(scalingGroupId);
  25. cscRequest.setImageId("centos_7_04_64_20G_alibase_201701015.vhd");
  26. cscRequest.setInstanceType("ecs.t1.xsmall");
  27. cscRequest.setSecurityGroupId("G0000000123456789"); // You can obtain the SecurityGroupId through the DescribeSecurityGroups API of ECS
  28. auto cscOutcome = client.createScalingConfiguration(cscRequest);
  29. if (cscOutcome.isSuccess())
  30. std::cout << "ScalingConfigurationId: " << cscOutcome.result().getScalingConfigurationId() << std::endl;
  31. }
  32. // Close the SDK
  33. AlibabaCloud::ShutdownSdk();
  34. return 0;
  35. }

Code example: specify the I/O optimized instance

  1. Model::CreateScalingConfigurationRequest cscRequest;
  2. cscRequest.setScalingGroupId(scalingGroupId);
  3. cscRequest.setImageId("centos_7_04_64_20G_alibase_201701015.vhd");
  4. cscRequest.setInstanceType("ecs.t1.xsmall");
  5. cscRequest.setIoOptimized("optimized"); // Specify the I/O optimized instance through the IoOptimized parameter
  6. cscRequest.setSecurityGroupId("G0000000123456789");
Thank you! We've received your feedback.