edit-icon download-icon

Server Load Balancer

Last Updated: Mar 20, 2018

Alibaba Cloud Server Load Balancer (SLB) is a traffic distribution control service that distributes the incoming traffic among multiple Elastic Compute Service (ECS) instances according to the configured forwarding rules. It expands the service capabilities of the application and increases the availability of the application. For more information, see Server Load Balancer documentation.

This tutorial uses the CreateLoadBalancer API of SLB to show you how to use Alibaba Cloud C++ SDK to call SLB APIs.

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

  1. #include <iostream>
  2. #include <alibabacloud/core/AlibabaCloud.h>
  3. #include <alibabacloud/slb/SlbClient.h>
  4. using namespace AlibabaCloud;
  5. using namespace AlibabaCloud::Slb;
  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. SlbClient client("<your-access-key-id>", "<your-access-key-secret>", configuration);
  13. // Create a request and set parameters
  14. Model::CreateLoadBalancerRequest request;
  15. request.setLoadBalancerName("my-sample-slb");
  16. request.setAddressType("internet");
  17. request.setInternetChargeType("paybytraffic");
  18. // Initiate the request and print the handling result
  19. auto outcome = client.createLoadBalancer(request);
  20. if(outcome.isSuccess())
  21. std::cout << "LoadBalancerId: " << outcome.result().getLoadBalancerId() << std::endl;
  22. // Close the SDK
  23. AlibabaCloud::ShutdownSdk();
  24. return 0;
  25. }
Thank you! We've received your feedback.