edit-icon download-icon

Virtual Private Cloud

Last Updated: Mar 20, 2018

Virtual Private Cloud (VPC) is a private network established in Alibaba Cloud. VPCs are logically isolated from other virtual networks in Alibaba Cloud. You have full control over your VPC, such as specifying the IP address range of your VPC, and configuring route tables and network gateways. You can also use Alibaba Cloud resources such as ECS, RDS, and SLB in your own VPC. For more information, see VPC documentation.

This tutorial uses the CreateVpc API of VPC to show you how to use Alibaba Cloud Java SDK to call VPC APIs.

  1. import java.util.UUID;
  2. import com.aliyuncs.DefaultAcsClient;
  3. import com.aliyuncs.IAcsClient;
  4. import com.aliyuncs.exceptions.ClientException;
  5. import com.aliyuncs.exceptions.ServerException;
  6. import com.aliyuncs.profile.DefaultProfile;
  7. import com.aliyuncs.vpc.model.v20160428.CreateVpcRequest;
  8. import com.aliyuncs.vpc.model.v20160428.CreateVpcResponse;
  9. public class Demo {
  10. public static void main(String[] args) {
  11. // Create and initialize the DefaultAcsClient instance
  12. DefaultProfile profile = DefaultProfile.getProfile(
  13. "<your-region-id>", // Your region ID
  14. "<your-access-key-id>", // Your AccessKey ID
  15. "<your-access-key-secret>"); // Your AccessKey Secret
  16. IAcsClient client = new DefaultAcsClient(profile);
  17. // Create a request and set parameters
  18. CreateVpcRequest request = new CreateVpcRequest();
  19. request.setVpcName("MyVpc");
  20. request.setCidrBlock("192.168.0.0/16");
  21. request.setClientToken(UUID.randomUUID().toString());
  22. // Initiate the request and handle the response or exceptions
  23. CreateVpcResponse response;
  24. try {
  25. response = client.getAcsResponse(request);
  26. String vpcId = response.getVpcId();
  27. System.out.println("Create vpc success, vpcId = " + vpcId);
  28. } catch (ServerException e) {
  29. e.printStackTrace();
  30. } catch (ClientException e) {
  31. e.printStackTrace();
  32. }
  33. }
  34. }
Thank you! We've received your feedback.