This topic describes how to use Alibaba Cloud SDK for Python to create an SNAT entry.
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 for the VPC.
- Create a NAT gateway in the VPC.
- Create an elastic IP address (EIP) in the China (Shanghai) region.
- Associate the EIP with the NAT gateway.
- Create an SNAT entry.
- Query the EIP that is associated with the NAT gateway.
- Query the NAT gateway.
- Delete the SNAT entry.
- Disassociate the EIP from the NAT gateway.
- Delete the NAT gateway.
- Release the EIP.
- Delete the vSwitch.
- Delete the VPC.
Procedure
Result
The following output is returned:
---------------------------create_vpc---------------------------
{
"ResourceGroupId": "rg-acfmxazxxxxxxxx",
"RouteTableId": "vtb-uf6a8ccj9ne58xxxxxxxx",
"VRouterId": "vrt-uf6qqqaf1o1ptxxxxxxxx",
"VpcId": "vpc-uf6hxer3h07wgxxxxxxxx",
"RequestId": "8F483A7B-8A38-47ED-85BD-1E83C075AEA4"
}
---------------------------create_vswitch---------------------------
{
"VSwitchId": "vsw-uf6lbov9tyetqxxxxxxxx",
"RequestId": "2EE2E11B-EF60-4C88-BE2A-F45517290B31"
}
---------------------------create_nat_gateway---------------------------
{
"NatGatewayId": "ngw-uf6l3c3rswubuxxxxxxxx",
"BandwidthPackageIds": {
"BandwidthPackageId": []
},
"ForwardTableIds": {
"ForwardTableId": [
"ftb-uf6086r1hyecbxxxxxxxx"
]
},
"RequestId": "9037D769-24C8-46AD-83F3-4C0538FA5970",
"SnatTableIds": {
"SnatTableId": [
"stb-uf6ppo11rsecmxxxxxxxx"
]
}
}
---------------------------allocate_eip_address---------------------------
{
"EipAddress": "101.xx.xx.110",
"ResourceGroupId": "rg-acfmxazxxxxxxxx",
"RequestId": "0DE621B4-6BDE-4E17-A294-8F71FBB9F710",
"AllocationId": "eip-uf6d311cpmr0nxxxxxxxx"
}
---------------------------associate_eip_address eip---------------------------
{
"RequestId": "C95B2EDC-F081-4784-B60B-2600F60E684D"
}
---------------------------create_snat_entry---------------------------
{
"SnatEntryId": "snat-uf6ppbwshdu40xxxxxxxx",
"RequestId": "BB9F8FD2-3CB5-4F84-8006-FE64BF3BEA06"
}
---------------------------describe_eip_address---------------------------
{
"TotalCount": 1,
"PageNumber": 1,
"PageSize": 10,
"EipAddresses": {
"EipAddress": [
{
"ISP": "BGP",
"ExpiredTime": "",
"InternetChargeType": "PayByBandwidth",
"IpAddress": "101.xx.xx.110",
"AllocationId": "eip-uf6d311cpmr0nxxxxxxxx",
"PrivateIpAddress": "",
"Status": "InUse",
"BandwidthPackageId": "",
"InstanceId": "ngw-uf6l3c3rswubuxxxxxxxx",
"InstanceRegionId": "cn-shanghai",
"RegionId": "cn-shanghai",
"AvailableRegions": {
"AvailableRegion": [
"cn-shanghai"
]
},
"ResourceGroupId": "rg-acfmxazxxxxxxxx",
"HasReservationData": false,
"InstanceType": "Nat",
"AllocationTime": "2019-04-24T11:20:09Z",
"Name": "",
"OperationLocks": {
"LockReason": []
},
"Mode": "NAT",
"BandwidthPackageType": "",
"BandwidthPackageBandwidth": "",
"Bandwidth": "5",
"HDMonitorStatus": "OFF",
"ChargeType": "PostPaid",
"SecondLimited": false,
"Descritpion": ""
}
]
},
"RequestId": "19052237-6E84-4258-89B9-05772C33C0DC"
}
---------------------------describe_nat_gateway---------------------------
{
"TotalCount": 1,
"PageNumber": 1,
"RequestId": "26CAA3FE-B400-4522-9582-2DAAF69129AE",
"PageSize": 10,
"NatGateways": {
"NatGateway": [
{
"Status": "Available",
"BandwidthPackageIds": {
"BandwidthPackageId": []
},
"VpcId": "vpc-uf6hxer3h07wgxxxxxxxx",
"Description": "",
"ForwardTableIds": {
"ForwardTableId": [
"ftb-uf6086r1hyecbxxxxxxxx"
]
},
"IpLists": {
"IpList": [
{
"UsingStatus": "UsedBySnatTable",
"IpAddress": "101.xx.xx.110",
"AllocationId": "eip-uf6d311cpmr0nxxxxxxxx"
}
]
},
"BusinessStatus": "Normal",
"RegionId": "cn-shanghai",
"CreationTime": "2019-04-24T11:20:06Z",
"NatGatewayId": "ngw-uf6l3c3rswubuxxxxxxxx",
"SnatTableIds": {
"SnatTableId": [
"stb-uf6ppo11rsecmxxxxxxxx"
]
},
"AutoPay": false,
"InstanceChargeType": "PostPaid",
"ExpiredTime": "",
"Spec": "Small",
"Name": ""
}
]
}
}
---------------------------delete_snat_entry---------------------------
{
"RequestId": "CDA82881-ACF0-4DD1-887B-A764F56F180D"
}
---------------------------unassociate_eip_address nat--------------------------
-
{
"RequestId": "140C46FF-0DB0-47F9-B0F4-3459DF117EAF"
}
---------------------------delete_nat_gateway---------------------------
{
"RequestId": "8709747C-6786-443C-8AEA-51647AA49769"
}
---------------------------release_eip_address---------------------------
{
"RequestId": "0BC21C23-0FB3-4594-8B14-6552DF788C93"
}
---------------------------delete_vswitch---------------------------
{
"RequestId": "16E840EC-E058-40C1-A5BF-8CDF672EA139"
}
---------------------------delete_vpc---------------------------
{
"RequestId": "B5F18126-FF2A-4005-9973-3984034DF0F4"
}