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

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

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

注意
确保您已经开通了弹性伸缩服务。
using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.Ess.Model.V20140828;

class Sample
{
    static void Main(string[] args)
    {
        // 创建客户端实例
        IClientProfile clientProfile = DefaultProfile.GetProfile("<your-region-id>", "<your-access-key-id>", "<your-access-key-secret>");
        DefaultAcsClient client = new DefaultAcsClient(clientProfile);
		
        try
        {
            // 创建伸缩组 (Scaling Group)
            CreateScalingGroupRequest csgRequest = new CreateScalingGroupRequest();
            csgRequest.MaxSize = 10;
            csgRequest.MinSize = 2;
            CreateScalingGroupResponse csgResponse = client.GetAcsResponse(csgRequest);
            String scalingGroupId = csgResponse.ScalingGroupId;
            Console.WriteLine("ScalingGroupId: {0}", scalingGroupId);
			
            // 创建伸缩配置(Scaling Configuration)
            CreateScalingConfigurationRequest cscRequest = new CreateScalingConfigurationRequest();
            cscRequest.ScalingGroupId = scalingGroupId;
            cscRequest.ImageId = "centos_7_04_64_20G_alibase_201701015.vhd";
            cscRequest.InstanceType = "ecs.t1.xsmall";
            cscRequest.SecurityGroupId = "G0000000123456789"; // 可以通过 ECS 的 DescribeSecurityGroups 接口获取 SecurityGroupId
            CreateScalingConfigurationResponse cscResponse = client.GetAcsResponse(cscRequest);
            Console.WriteLine("ScalingConfigurationId: {0}", cscResponse.ScalingConfigurationId);
        }
        catch (ServerException e)
        {
            Console.WriteLine(e.ErrorCode);
            Console.WriteLine(e.ErrorMessage);
        }
        catch (ClientException e)
        {
            Console.WriteLine(e.ErrorCode);
            Console.WriteLine(e.ErrorMessage);
        }
    }
}

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


CreateScalingConfigurationRequest cscRequest = new CreateScalingConfigurationRequest();
cscRequest.ScalingGroupId = scalingGroupId;
cscRequest.ImageId = "centos_7_04_64_20G_alibase_201701015.vhd";
cscRequest.InstanceType = "ecs.t1.xsmall";
cscRequest.IoOptimized = "optimized";
cscRequest.SecurityGroupId = "G0000000123456789";