edit-icon download-icon

Elastic Compute Service

Last Updated: Mar 20, 2018

Elastic Compute Service (ECS) is a type of computing service that features elastic processing capabilities. ECS has a simpler and more efficient management mode than physical servers. You can create instances, change the operating system, and add or release any quantity of ECS instances at any time to fit your business needs. For more information about ECS, see Elastic Compute Service Documentation.

Example overview

The example in this section shows you how to create an ECS instance by creating a CreateInstanceRequest. To create an ECS instance, obtain the following information:

Code example

Note: Running the code in this example will create an ECS instance and generate fees.

  1. #include <iostream>
  2. #include <alibabacloud/core/AlibabaCloud.h>
  3. #include <alibabacloud/ecs/EcsClient.h>
  4. using namespace AlibabaCloud;
  5. using namespace AlibabaCloud::Ecs;
  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. EcsClient client("<your-access-key-id>", "<your-access-key-secret>", configuration);
  13. // Create a request and set parameters
  14. Model::CreateInstanceRequest request;
  15. request.setImageId("_32_23c472_20120822172155_aliguest.vhd");
  16. request.setInstanceType("ecs.t1.small");
  17. // Initiate the request and print the handling result
  18. auto outcome = client.createInstance(request);
  19. if(outcome.isSuccess())
  20. std::cout << "InstanceId: " << outcome.result().getInstanceId() << std::endl;
  21. // Close the SDK
  22. AlibabaCloud::ShutdownSdk();
  23. return 0;
  24. }
Thank you! We've received your feedback.