This topic describes how to use Alibaba Cloud SDK for Python to associate an elastic IP address (EIP) with an Elastic Compute Service (ECS) instance.
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 an EIP in the China (Hangzhou) region.
- Associate the EIP with an ECS instance.
- Query the EIP that is associated with the ECS instance.
- Modify the maximum bandwidth and name of the EIP.
- Query the modified EIP.
- Disassociate the EIP from the ECS instance.
- Releases the EIP.
Procedure
Result
The following output is returned:
---------------------------allocate_eip_address---------------------------
{
"EipAddress": "47.XX.XX.23",
"ResourceGroupId": "rg-acfm4od****",
"RequestId": "C438312E-F7A4-4A04-901F-D22FE23EDB4D",
"AllocationId": "eip-bp1wybucvhhx5****"
}
---------------------------associate_eip_address---------------------------
{
"RequestId": "6EC6605E-3D2B-4EE8-BD13-F1964CD1EAB1"
}
---------------------------describe_eip_address---------------------------
{
"TotalCount": 1,
"PageNumber": 1,
"PageSize": 10,
"EipAddresses": {
"EipAddress": [
{
"ISP": "BGP",
"ExpiredTime": "",
"InternetChargeType": "PayByBandwidth",
"IpAddress": "47.XX.XX.23",
"AllocationId": "eip-bp1wybucvhhx5****",
"PrivateIpAddress": "",
"Status": "InUse",
"BandwidthPackageId": "",
"InstanceId": "i-bp1e82xlhob2****",
"InstanceRegionId": "cn-hangzhou",
"RegionId": "cn-hangzhou",
"AvailableRegions": {
"AvailableRegion": [
"cn-hangzhou"
]
},
"ResourceGroupId": "rg-acfm4od****",
"HasReservationData": false,
"InstanceType": "EcsInstance",
"AllocationTime": "2019-04-17T11:57:43Z",
"Name": "",
"OperationLocks": {
"LockReason": []
},
"Mode": "NAT",
"BandwidthPackageType": "",
"BandwidthPackageBandwidth": "",
"Bandwidth": "5",
"HDMonitorStatus": "OFF",
"ChargeType": "PostPaid",
"SecondLimited": false,
"Descritpion": ""
}
]
},
"RequestId": "8715A878-A808-4CC4-AAD5-E414FDAB5B0E"
}
---------------------------modify_eip_address---------------------------
{
"RequestId": "2108AE1C-94FB-475D-BFEE-EC88598BF6A6"
}
---------------------------describe_eip_address---------------------------
{
"TotalCount": 1,
"PageNumber": 1,
"PageSize": 10,
"EipAddresses": {
"EipAddress": [
{
"ISP": "BGP",
"ExpiredTime": "",
"InternetChargeType": "PayByBandwidth",
"IpAddress": "47.XX.XX.23",
"AllocationId": "eip-bp1wybucvhhx5****",
"PrivateIpAddress": "",
"Status": "InUse",
"BandwidthPackageId": "",
"InstanceId": "i-bp1e82xlhob2****",
"InstanceRegionId": "cn-hangzhou",
"RegionId": "cn-hangzhou",
"AvailableRegions": {
"AvailableRegion": [
"cn-hangzhou"
]
},
"ResourceGroupId": "rg-acfm4od****",
"HasReservationData": false,
"InstanceType": "EcsInstance",
"AllocationTime": "2019-04-17T11:57:43Z",
"Name": "EIP_NEW_NAME",
"OperationLocks": {
"LockReason": []
},
"Mode": "NAT",
"BandwidthPackageType": "",
"BandwidthPackageBandwidth": "",
"Bandwidth": "50",
"HDMonitorStatus": "OFF",
"ChargeType": "PostPaid",
"SecondLimited": false,
"Descritpion": ""
}
]
},
"RequestId": "6694D35B-B5DD-4506-8AB1-2D16477646DE"
}
---------------------------unassociate_eip_address---------------------------
{
"RequestId": "EDE86CF6-EE68-4922-B919-85A4F11BF668"
}
---------------------------release_eip_address---------------------------
{
"RequestId": "53FEE062-B595-4D64-AB47-834015D32888"
}