Assigns a public IP address to an ECS instance. We recommend that you call the ModifyInstanceNetworkSpec operation to assign a public IP address.
Operation description
Before you begin
-
Before you assign a public IP address, the instance must be in the Running (
Running) or Stopped (Stopped) state. -
If
"LockReason" : "security"is included in theOperationLocksof an instance that is locked for security reasons, you cannot assign a public IP address to the instance. -
Make sure that the public bandwidth of the instance is greater than 0 before you call this operation. You can call the ModifyInstanceNetworkSpec operation to adjust the bandwidth.
Precautions
-
Only users in the whitelist can specify the public IP address by using the
IpAddressparameter. If the public bandwidth is greater than 0, you can setInstanceIdto allocate a random public IP address. If the public bandwidth is 0, call the ModifyInstanceNetworkSpec operation to adjust the bandwidth before you call this operation to allocate a public IP address. -
Only one public IP address can be allocated to an instance. If the instance already has a public IP address, the existing attached public IP address
IpAddressis returned. -
The new public IP address takes effect after you restart the instance (RebootInstance) or start the instance (StartInstance).
In addition to assigning a public IP address, you can associate an Elastic IP Address (EIP) with a VPC-connected ECS instance. For more information, see AssociateEipAddress.
Try it now
Test
RAM authorization
|
Action |
Access level |
Resource type |
Condition key |
Dependent action |
|
ecs:AllocatePublicIpAddress |
create |
*Instance
|
None | None |
Request parameters
|
Parameter |
Type |
Required |
Description |
Example |
| InstanceId |
string |
Yes |
The instance ID of the instance to which you want to allocate a public IP address. Note
The public bandwidth of the instance must be greater than 0. |
i-bp1gtjxuuvwj17zr**** |
| IpAddress |
string |
No |
The public IP address of the instance. If this parameter is left empty, the system randomly assigns an IP address. Note
Only users in the whitelist can specify this parameter. Regular users cannot specify an IP address. |
112.124.**.** |
| VlanId |
string |
No |
The VLAN ID of the instance. Note
This parameter will be deprecated. For better compatibility, use other parameters. |
720 |
Response elements
|
Element |
Type |
Description |
Example |
|
object |
|||
| IpAddress |
string |
The public IP address of the instance. |
112.124.**.** |
| RequestId |
string |
The request ID. |
473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E |
Examples
Success response
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.CloudboxNotSupport | This operation is denied, because the specified ECS instance which is in the Cloudbox dose not support PublicIp or Eip. | |
| 400 | OperationDenied.DedicatedRegionNotSupported | This operation is denied, because the specified ECS instance which is in the dedicated region dose not support PublicIp or Eip. | error of api not supported by the exclusive cloud |
| 500 | InternalError | The request processing has failed due to some unknown error. | |
| 500 | InvalidOperation.AllocateIpFailed | Failed to allocate the specific IP, please ensure the IP is available. | Failed to assign specific IP, please make sure the IP is available. |
| 403 | IncorrectInstanceStatus | The current status of the resource does not support this operation. | |
| 403 | InstanceLockedForSecurity | The specified operation is denied as your instance is locked for security reasons. | The instance is locked for security reasons. Contact security technical support for assistance. |
| 403 | InstanceExpiredOrInArrears | The specified operation is denied as your prepay instance is expired (prepay mode) or in arrears (afterpay mode). | |
| 403 | IpInUse | The specified IP is already in use. | The specified IP address is already in use on another instance. |
| 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. | |
| 404 | InvalidInstanceId.NotFound | The specified InstanceId does not exist. | The specified instanceId is invalid. |
| 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. |
| 409 | OperationConflict | Request was denied due to conflict with a previous request,please try again later. | The requested resource conflicts with a previous request. |
| 409 | TokenProcessing | The previous token request is still processing. Please try again later. |
See Error Codes for a complete list.
Release notes
See Release Notes for a complete list.