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 as an example to show you how to use Alibaba Cloud Python SDK to call VPC APIs.

  1. import json
  2. from aliyunsdkcore.client import AcsClient
  3. from aliyunsdkcore.acs_exception.exceptions import ClientException
  4. from aliyunsdkcore.acs_exception.exceptions import ServerException
  5. from aliyunsdkvpc.request.v20160428 import CreateVpcRequest
  6. from aliyunsdkvpc.request.v20160428 import DescribeVpcAttributeRequest
  7. # Create the AcsClient instance
  8. client = AcsClient(
  9. "<your-access-key-id>",
  10. "<your-access-key-secret>",
  11. "<your-region-id>"
  12. );
  13. # Create a VPC
  14. request = CreateVpcRequest.CreateVpcRequest()
  15. response = client.do_action_with_exception(request)
  16. vpc_id = json.loads(response)['VpcId']
  17. print "VPC ID is", vpc_id
  18. # Obtain and print the attributes of the VPC
  19. request = DescribeVpcAttributeRequest.DescribeVpcAttributeRequest()
  20. request.set_VpcId(vpc_id)
  21. response = client.do_action_with_exception(request)
  22. print response
Thank you! We've received your feedback.