Associates an elastic IP address (EIP) with an instance in the same region.

Description

You can associate an EIP with an Elastic Compute Service (ECS) instance, an internal-facing Server Load Balancer (SLB) instance, a secondary elastic network interface (ENI), a NAT gateway, or a high-availability virtual IP address (HAVIP) in the same region. The ECS instance and internal-facing SLB instance must be deployed in a virtual private cloud (VPC).

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

Request parameters

Parameter Type Required Example Description
Action String Yes AssociateEipAddress

The operation that you want to perform. Set the value to AssociateEipAddress.

RegionId String Yes cn-hangzhou

The ID of the region to which the EIP belongs.

You can call the DescribeRegions operation to query the most recent region list.

AllocationId String Yes eip-2zeerraiwb7ujsxdc****

The ID of the EIP that you want to associate with an instance.

InstanceId String Yes i-2zebb08phyczzawe****

The ID of the instance with which you want to associate the EIP.

NAT gateways, SLB instances, ECS instances, secondary ENIs, and HAVIPs are supported.

InstanceType String No EcsInstance

The type of instance with which you want to associate the EIP. Valid values:

  • Nat: a NAT gateway
  • SlbInstance: an SLB instance
  • EcsInstance (default): an ECS instance in a VPC
  • NetworkInterface: a secondary ENI
  • HaVip: an HAVIP
Note If you do not set this parameter, the type of the instance with which you want to associate the EIP is EcsInstance. If the type of the instance with which you want to associate the EIP is not EcsInstance, this parameter is required.
InstanceRegionId String No cn-hangzhou

The region ID of the instance with which you want to associate the EIP.

Note This parameter is required only when the EIP is associated with a shared-bandwidth Global Accelerator (GA) instance.
PrivateIpAddress String No 192.168.XX.XX

An IP address in the CIDR block of the vSwitch.

If you do not set this parameter, the system allocates a private IP address based on the VPC ID and vSwitch ID.

Mode String No NAT

The association mode. Valid values:

  • NAT (default): NAT mode
  • MULTI_BINDED: multi-EIP-to-ENI mode
  • BINDED: cut-through mode

This parameter is required only when InstanceType is set to NetworkInterface.

ClientToken String No 0c593ea1-3bea-11e9-b96b-88e9fe63****

The client token that is used to ensure the idempotence of the request. You can use the client to generate the value, but you must make sure that it is unique among different requests. The ClientToken value can contain only ASCII characters and cannot exceed 64 characters in length.

Response parameters

Parameter Type Example Description
RequestId String 0ED8D006-F706-4D23-88ED-E11ED28DCAC0

The ID of the request.

Examples

Sample requests

http(s)://[Endpoint]/?Action=AssociateEipAddress
&RegionId=cn-hangzhou
&AllocationId=eip-2zeerraiwb7ujsxdc****
&InstanceId=i-2zebb08phyczzawe****
&InstanceType=EcsInstance
&InstanceRegionId=cn-hangzhou
&PrivateIpAddress=192.168.XX.XX
&Mode=NAT
&ClientToken=0c593ea1-3bea-11e9-b96b-88e9fe63****
&Common request parameters

Sample success responses

XML format

HTTP/1.1 200 OK
Content-Type:application/xml

<AssociateEipAddressResponse>
    <RequestId>0ED8D006-F706-4D23-88ED-E11ED28DCAC0</RequestId>
</AssociateEipAddressResponse>

JSON format

HTTP/1.1 200 OK
Content-Type:application/json

{
  "RequestId" : "0ED8D006-F706-4D23-88ED-E11ED28DCAC0"
}

Error codes

HttpCode Error code Error message Description
400 InvalidAssociation.Duplicated Specified instance already is associated. The error message returned because an EIP or a GA instance is already associated with the specified instance. You must disassociate the EIP or GA instance from the specified instance before you can perform the operation.
400 OperationDenied Specified instance is not in VPC. The error message returned because the specified instance does not exist in the VPC.
400 InvalidParameter.Mismatch Specified elastic IP address and ECS instance are not in the same region. The error message returned because the specified EIP and ECS instance do not belong to the same region.
400 IncorrectEipStatus Current elastic IP status does not support this operation The error message returned because the status of the EIP does not support the operation.
400 IncorrectInstanceStatus Current instance status does not support this operation. The error message returned because this operation cannot be performed while the instance is in the current state.
400 InvalidInstanceType.ValueNotSupported The specified value of InstanceType is not supported. The error message returned because InstanceType is set to an invalid value.
400 InvalidParameter The specified parameter is not valid. The error message returned because the parameter is set to an invalid value.
400 OperationDenied Eip of default vpc not allow this operation The error message returned because the operation is not supported by EIPs in the default VPC.
400 Forbbiden The eip instance owener error The error message returned because you are unauthorized to perform the operation on the EIP.
400 InvalidBindingStatus The eip binding status invalid. The error message returned because the EIP is in an invalid state.
400 BIND_INSTANCE_HAVE_PORTMAP_OR_BIND_EIP The instance may have portMap or already bind eip. The error message returned because a port forwarding rule is configured for the ECS instance. Delete the port forwarding rule and try again.
400 BIND_INSTANCE_OWENER_ERROR Cannot operate the eip. The error message returned because you are unauthorized to manage the specified EIP.
400 InvalidParams.NotFound instance not found The error message returned because the specified instance does not exist.
400 OperationDenied.CloudBoxResourceExist The operation is not allowed because there are resources related to the cloud box in VPC. The error message returned because the VPC contains CloudBox-related resources and the operation is not allowed.
400 OperationDenied.CloudBoxVSwitchExist The operation is not allowed because a cloud box type vSwitch exists in VPC. The error message returned because the VPC contains a vSwitch of the CloudBox type and the operation is not allowed.
404 InvalidInstanId.NotFound Specified instance does not exist. The error message returned because the specified instance does not exist. Check whether the instance ID is valid.
404 InvalidAllocationId.NotFound Specified allocation ID is not found The error message returned because the specified EIP does not exist. Check whether the specified value is valid.
503 ServiceUnavailable The request has failed due to a temporary failure of the server. The error message returned because the request failed due to a temporary malfunction of the server.

For a list of error codes, visit the API Error Center.