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.

Prerequisite

  • 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. import json
  2. from aliyunsdkcore.client import AcsClient
  3. from aliyunsdkcore.acs_exception.exceptions import ClientException
  4. from aliyunsdkcore.acs_exception.exceptions import ServerException
  5. from aliyunsdkess.request.v20140828 import CreateScalingGroupRequest
  6. from aliyunsdkess.request.v20140828 import CreateScalingConfigurationRequest
  7. # Initialize the AcsClient instance
  8. client = AcsClient(
  9. "<your-access-key-id>",
  10. "<your-access-key-secret>",
  11. "<your-region-id>"
  12. );
  13. # Create a scaling group
  14. request = CreateScalingGroupRequest.CreateScalingGroupRequest()
  15. request.set_MaxSize(10)
  16. request.set_MinSize(2)
  17. response = client.do_action_with_exception(request)
  18. scaling_group_id = json.loads(response)['ScalingGroupId']
  19. print "ScalingGroupId is", scaling_group_id
  20. # Configure the scaling group
  21. request = CreateScalingConfigurationRequest.CreateScalingConfigurationRequest()
  22. request.set_ScalingGroupId(scaling_group_id)
  23. # ImageId can be obtained by the DescribeImages API
  24. request.set_ImageId('centos_7_04_64_20G_alibase_201701015.vhd')
  25. request.set_InstanceType('ecs.t1.xsmall')
  26. # SecurityGroupId can be obtained by the DescribeSecurityGroups API
  27. request.set_SecurityGroupId('sg-bp14z29vpgy2t7spfxw8')
  28. response = client.do_action_with_exception(request)
  29. print response

Code example: specify I/O-optimized instances

  1. # Configure the scaling group
  2. request = CreateScalingConfigurationRequest.CreateScalingConfigurationRequest()
  3. request.set_ScalingGroupId(scaling_group_id)
  4. # ImageId can be obtained by the DescribeImages API
  5. request.set_ImageId('centos_7_04_64_20G_alibase_201701015.vhd')
  6. request.set_InstanceType('ecs.t1.xsmall')
  7. request.set_IoOptimized('optimized')
  8. # SecurityGroupId can be obtained by the DescribeSecurityGroups API
  9. request.set_SecurityGroupId('sg-bp14z29vpgy2t7spfxw8')
  10. response = client.do_action_with_exception(request)
  11. print response
Thank you! We've received your feedback.