All Products
Search
Document Center

Elastic Compute Service:AllocatePublicIpAddress

Last Updated:May 16, 2024

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

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer.

Authorization information

There is currently no authorization information disclosed in the API.

Request parameters

ParameterTypeRequiredDescriptionExample
InstanceIdstringYes

The ID of the instance to which you want to assign a public IP address.

i-bp1gtjxuuvwj17zr****
IpAddressstringNo

The public IP address. If you leave this parameter empty, the system randomly assigns a public IP address to the instance.

112.124.**.**
VlanIdstringNo

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

ParameterTypeDescriptionExample
object
IpAddressstring

The public IP address.

112.124.**.**
RequestIdstring

The request ID.

473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E

Examples

Sample success responses

JSONformat

{
  "IpAddress": "112.124.**.**",
  "RequestId": "473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E"
}

Error codes

HTTP status codeError codeError messageDescription
400InvalidOperation.AllocateFailedThe current instance failed to allocate public IP, please try again later.-
400InvalidIpAddress.MalformedThe specified parameter "IpAddress" is not valid.-
400OperationDeniedSpecified operation is denied as your instance is in VPC.The operation is not supported while the instance resides in a VPC.
400InsufficientPublicIpIp address not found.-
400AllocateIpInvalidInstanceBandwidthOperationDenied 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.
400OperationDeniedThe specified parameter "VlanId" is not valid or vlan has not enough IP address.-
400OperationDeniedThe specified instance already has a public IP.-
400OperationDenied.CloudboxNotSupportThis operation is denied, because the specified ECS instance which is in the Cloudbox dose not support PublicIp or Eip.-
400OperationDenied.DedicatedRegionNotSupportedThis 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
403IncorrectInstanceStatusThe current status of the resource does not support this operation.The resource is in a state that does not support the current operation.
403InstanceLockedForSecurityThe specified operation is denied as your instance is locked for security reasons.-
403InstanceExpiredOrInArrearsThe 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.
403IpInUseThe specified IP is already in use.-
403AllocatedAlreadyThere 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.
403AllocateIp.FailThe specified instance fails to allocate ip, please try again.-
403NAT_PUBLIC_IP_BINDING_FAILEDBinding nat public ip failed.-
403NAT_PUBLIC_IP_ALLOCATE_FAILEDNat public ip binding failed.The public IP address cannot be associated.
403InvalidIpAddress.NotPublicThe specified IP is not public address.-
403AllocatedAlreadyAn IpAddress has been assigned to the specified instance.-
404InvalidInstanceId.NotFoundThe specified InstanceId does not exist.The specified instance does not exist.
404InvalidVlanId.NotFoundThe VlanId provided does not exist in our records.The specified VLAN ID does not exist.
404InvalidIpAddress.NotFoundThe specified IP is not in the specified vlan.The specified IP address is not in the specified VLAN.
500InternalErrorThe 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 timeSummary of changesOperation
2023-10-10The Error code has changedsee changesets
Change itemChange content
Error CodesThe Error code has changed.
    Error Codes 400 change
    delete Error Codes: 403
    delete Error Codes: 404
    delete Error Codes: 500