本示例介绍如何使用阿里云Python SDK调用弹性伸缩的CreateScalingGroup接口创建一个弹性伸缩组和如何通过IoOptimized参数指定 I/O 优化实例。

弹性伸缩是根据用户的业务需求和策略,自动调整其弹性计算资源的管理服务。根据业务需求,您可以自动地调整其弹性计算资源。

阿里云2000元代金券免费领,最新优惠1折抢购,2核4G云服务器仅799元/3年,新老用户同享,立即抢购>>>

示例代码:创建弹性伸缩组

注意 确保您已经开通了弹性伸缩服务。

import json  from aliyunsdkcore.client import AcsClient from aliyunsdkcore.acs_exception.exceptions import ClientException from aliyunsdkcore.acs_exception.exceptions import ServerException from aliyunsdkess.request.v20140828 import CreateScalingGroupRequest from aliyunsdkess.request.v20140828 import CreateScalingConfigurationRequest  # 创建 AcsClient 实例 client = AcsClient(    "<your-access-key-id>",    "<your-access-key-secret>",    "<your-region-id>" );  # 创建伸缩组 (Scaling Group) request = CreateScalingGroupRequest.CreateScalingGroupRequest() request.set_MaxSize(10) request.set_MinSize(2) response = client.do_action_with_exception(request) scaling_group_id = json.loads(response)['ScalingGroupId'] print "ScalingGroupId is", scaling_group_id  # 创建伸缩配置 (Scaling Configuration) request = CreateScalingConfigurationRequest.CreateScalingConfigurationRequest() request.set_ScalingGroupId(scaling_group_id) # 可以通过 ECS 的 DescribeImages 接口获取 ImageId request.set_ImageId('centos_7_04_64_20G_alibase_201701015.vhd') request.set_InstanceType('ecs.t1.xsmall')  # 可以通过 ECS 的 DescribeSecurityGroups 接口获取 SecurityGroupId request.set_SecurityGroupId('sg-bp14z29vpgy2t7spfxw8') response = client.do_action_with_exception(request) print response

示例代码:指定 I/O优化实例

# 创建伸缩配置 (Scaling Configuration) request = CreateScalingConfigurationRequest.CreateScalingConfigurationRequest() request.set_ScalingGroupId(scaling_group_id)  # 可以通过 ECS 的 DescribeImages 接口获取 ImageId request.set_ImageId('centos_7_04_64_20G_alibase_201701015.vhd') request.set_InstanceType('ecs.t1.xsmall') request.set_IoOptimized('optimized')  # 可以通过 ECS 的 DescribeSecurityGroups 接口获取 SecurityGroupId request.set_SecurityGroupId('sg-bp14z29vpgy2t7spfxw8') response = client.do_action_with_exception(request) print response