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

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

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

注意
确保您已经开通了弹性伸缩服务。
#include <iostream>
#include <alibabacloud/core/AlibabaCloud.h>
#include <alibabacloud/ess/EssClient.h>

using namespace AlibabaCloud;
using namespace AlibabaCloud::Ess;

int main(int argc, char** argv)
{
    // 初始化 SDK
    AlibabaCloud::InitializeSdk();
	
    // 创建客户端实例
    ClientConfiguration configuration("<your-region-id>");
    EssClient client("<your-access-key-id>", "<your-access-key-secret>", configuration);
	
    // 创建伸缩组 (Scaling Group)
    Model::CreateScalingGroupRequest csgRequest;
    csgRequest.setMaxSize(10);
    csgRequest.setMinSize(2);
    auto csgOutcome = client.createScalingGroup(csgRequest);
    if (csgOutcome.isSuccess())
    {
        std::string scalingGroupId = csgOutcome.result().getScalingGroupId();
        std::cout << "ScalingGroupId: " << scalingGroupId << std::endl;
		
        // 创建伸缩配置(Scaling Configuration)
        Model::CreateScalingConfigurationRequest cscRequest;
        cscRequest.setScalingGroupId(scalingGroupId);
        cscRequest.setImageId("centos_7_04_64_20G_alibase_201701015.vhd");
        cscRequest.setInstanceType("ecs.t1.xsmall");
        cscRequest.setSecurityGroupId("G0000000123456789"); // 可以通过 ECS 的 DescribeSecurityGroups 接口获取 SecurityGroupId
        auto cscOutcome = client.createScalingConfiguration(cscRequest);
        if (cscOutcome.isSuccess())
            std::cout << "ScalingConfigurationId: " << cscOutcome.result().getScalingConfigurationId() << std::endl;
    }
	
    // 关闭 SDK
    AlibabaCloud::ShutdownSdk();
    return 0;
}

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

Model::CreateScalingConfigurationRequest cscRequest;
cscRequest.setScalingGroupId(scalingGroupId);
cscRequest.setImageId("centos_7_04_64_20G_alibase_201701015.vhd");
cscRequest.setInstanceType("ecs.t1.xsmall");
cscRequest.setIoOptimized("optimized");    // 通过IoOptimized参数指定 I/O 优化实例
cscRequest.setSecurityGroupId("G0000000123456789");