Assigns a public IP address to an Elastic Compute Service (ECS) instance.
Operation description
Take note of the following items:
- The instance to which you want to assign a public IP address must be in the Running or Stopped state.````
- If
OperationLocks
in the response of the DescribeInstances operation contains"LockReason" : "security"
for an instance, the instance is locked for security reasons and cannot be assigned a public IP address. - You can assign only one public IP address to an instance. If the instance already has a public IP address, the
AllocatedAlready
error is returned. - After you assign a public IP address to an instance, you must restart the instance ( RebootInstance ) or start the instance ( StartInstance ) to make the public IP address take effect.
If an instance resides in a virtual private cloud (VPC), you can assign a public IP address to the instance or associate an elastic IP address (EIP) with the instance. For more information, see AssociateEipAddress .
Note
After you associate an EIP with an instance that resides in a VPC, you cannot assign a public IP address to the instance.
Debugging
Authorization information
There is currently no authorization information disclosed in the API.
Request parameters
Parameter | Type | Required | Description | Example |
---|---|---|---|---|
InstanceId | string | Yes | The ID of the instance to which you want to assign a public IP address. | i-bp1gtjxuuvwj17zr**** |
IpAddress | string | No | The public IP address. If you leave this parameter empty, the system randomly assigns a public IP address to the instance. | 112.124.**.** |
VlanId | string | No | The virtual LAN (VLAN) ID of the instance. Note
This parameter will be removed in the future. To ensure future compatibility, we recommend that you use other parameters.
| 720 |
Response parameters
Examples
Sample success responses
JSON
format
{
"IpAddress": "112.124.**.**",
"RequestId": "473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E"
}
Error codes
HTTP status code | Error code | Error message | Description |
---|---|---|---|
400 | InvalidOperation.AllocateFailed | The current instance failed to allocate public IP, please try again later. | - |
400 | InvalidIpAddress.Malformed | The specified parameter "IpAddress" is not valid. | - |
400 | OperationDenied | Specified operation is denied as your instance is in VPC. | The operation is not supported while the instance resides in a VPC. |
400 | InsufficientPublicIp | Ip address not found. | - |
400 | AllocateIpInvalidInstanceBandwidth | OperationDenied The InternetMaxBandwidthOut of the specified instance cannot be less than 0. | The operation is not supported while the maximum outbound public bandwidth is not greater than 0 Mbit/s. |
400 | OperationDenied | The specified parameter "VlanId" is not valid or vlan has not enough IP address. | - |
400 | OperationDenied | The specified instance already has a public IP. | - |
400 | OperationDenied.CloudboxNotSupport | This operation is denied, because the specified ECS instance which is in the Cloudbox dose not support PublicIp or Eip. | - |
403 | IncorrectInstanceStatus | The current status of the resource does not support this operation. | The resource is in a state that does not support the current operation. |
403 | InstanceLockedForSecurity | The specified operation is denied as your instance is locked for security reasons. | - |
403 | InstanceExpiredOrInArrears | The specified operation is denied as your prepay instance is expired (prepay mode) or in arrears (afterpay mode). | The subscription instance has expired. You must renew the instance before you can proceed. |
403 | IpInUse | The specified IP is already in use. | - |
403 | AllocatedAlready | There is an IpAddress allocated already for the specified instance. | The instance to which you attempt to assign an IP address is already assigned another IP address. |
403 | AllocateIp.Fail | The specified instance fails to allocate ip, please try again. | - |
403 | NAT_PUBLIC_IP_BINDING_FAILED | Binding nat public ip failed. | - |
403 | NAT_PUBLIC_IP_ALLOCATE_FAILED | Nat public ip binding failed. | The public IP address cannot be associated. |
403 | InvalidIpAddress.NotPublic | The specified IP is not public address. | - |
403 | AllocatedAlready | An IpAddress has been assigned to the specified instance. | - |
404 | InvalidInstanceId.NotFound | The specified InstanceId does not exist. | The specified instance does not exist. |
404 | InvalidVlanId.NotFound | The VlanId provided does not exist in our records. | The specified VLAN ID does not exist. |
404 | InvalidIpAddress.NotFound | The specified IP is not in the specified vlan. | The specified IP address is not in the specified VLAN. |
500 | InternalError | The request processing has failed due to some unknown error. | An internal error has occurred. Try again later. |
For a list of error codes, visit the Service error codes.
Change history
Change time | Summary of changes | Operation | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
2023-10-10 | The Error code has changed | see changesets | ||||||||||
|