This topic describes how to use Alibaba Cloud SDK for Python to create a NAT gateway.
Prerequisites
Before you use Alibaba Cloud SDK for Python, make sure that the following requirements
are met:
- An Alibaba Cloud account and the AccessKey pair are obtained. You can create and view your AccessKey pair on the Security Management page of the Alibaba Cloud Management Console.
- Make sure that Alibaba Cloud SDK for Python is installed. For more information, see aliyun-python-sdk-vpc 3.0.12.
- The VPC Python example library is downloaded.
Go to the directory where the setup.py file is stored, and run the following command to initialize the environment:
python setup.py install
Background information
- Create a virtual private cloud (VPC) in the China (Shanghai) region.
- Create a vSwitch in the VPC.
- Create a NAT gateway for the VPC.
- Query the NAT gateway.
- Delete the NAT gateway.
- Delete the vSwitch.
- Delete the VPC.
Procedure
Result
The following output is returned:
---------------------------create_vpc---------------------------
{
"ResourceGroupId": "rg-acfmxaz****",
"RouteTableId": "vtb-uf6wzp25d8lkb****",
"VRouterId": "vrt-uf6di7voecmyq****",
"VpcId": "vpc-uf63cqupghmk1****",
"RequestId": "97D36E19-F789-424F-A473-660D63EF8CF9"
}
---------------------------create_vswitch---------------------------
{
"VSwitchId": "vsw-uf6fovepnk4****",
"RequestId": "18DA0E81-34A6-4877-9771-E2C4EEEBADD1"
}
---------------------------create_nat_gateway---------------------------
{
"NatGatewayId": "ngw-uf6mfrcmzktst****",
"BandwidthPackageIds": {
"BandwidthPackageId": []
},
"ForwardTableIds": {
"ForwardTableId": [
"ftb-uf6411str8n9s****"
]
},
"RequestId": "B1F791C8-73B1-46C5-8A20-726A615BC627",
"SnatTableIds": {
"SnatTableId": [
"stb-uf6t4eijvq3ae****"
]
}
}
---------------------------describe_nat_gateway---------------------------
{
"TotalCount": 1,
"PageNumber": 1,
"RequestId": "1F9303B1-4024-4A92-B67E-FB6BE1DC76D1",
"PageSize": 10,
"NatGateways": {
"NatGateway": [
{
"Status": "Available",
"BandwidthPackageIds": {
"BandwidthPackageId": []
},
"VpcId": "vpc-uf63cqupghmk1****",
"Description": "",
"ForwardTableIds": {
"ForwardTableId": [
"ftb-uf6411str8n9s****"
]
},
"IpLists": {
"IpList": []
},
"BusinessStatus": "Normal",
"RegionId": "cn-shanghai",
"CreationTime": "2019-04-24T09:09:12Z",
"NatGatewayId": "ngw-uf6mfrcmzktst****",
"SnatTableIds": {
"SnatTableId": [
"stb-uf6t4eijvq3ae****"
]
},
"AutoPay": false,
"InstanceChargeType": "PostPaid",
"ExpiredTime": "",
"Spec": "Small",
"Name": ""
}
]
}
}
---------------------------delete_nat_gateway---------------------------
{
"RequestId": "A0B71FE4-4756-4D91-899E-1DFA52D8615E"
}
---------------------------delete_vswitch---------------------------
{
"RequestId": "F224307E-3DE4-4415-AE19-DDCF24695462"
}
---------------------------delete_vpc---------------------------
{
"RequestId": "1BFFCBC3-7F83-436C-96E9-CA4A620072DA"
}