Associates an Elastic IP address with a cloud product instance in the same region.

API description

Note the following when you call this action:

  • You can associate an Elastic IP address with an Elastic Compute Service (ECS) instance in a Virtual Private Cloud (VPC), a Server Load Balancer (SLB) in a VPC, a secondary Elastic Network Interface (ENI) in a VPC, or a NAT Gateway. The associated instance must be in the same region as the Elastic IP address.
  • Before you associate an Elastic IP address with a NAT Gateway, make sure that no NAT bandwidth package exists under your account before November 3, 2017.

    If you have created a NAT bandwidth package for a NAT Gateway before November 3, 2017, to associate an Elastic IP address with the NAT Gateway, see Why am I unable to associate an Elastic IP address with a NAT Gateway in the NAT Gateway console.

Make the API call

You can use OpenAPI Explorer to make API calls, search for API calls, perform debugging, and generate SDK example code.

Request parameters

Parameter Type Required? Example value Description
Action String Yes AssociateEipAddress

The name of this action. Value: AssociateEipAddress.

AllocationId String Yes eip-2zeerraiwb7ujsxdc****

The ID of the Elastic IP address.

InstanceId String Yes i-2zebb08phyczzawe****

The ID of the instance to be associated with the Elastic IP address.

RegionId String Yes cn-hangzhou

The ID of the region to which the Elastic IP address belongs.

InstanceRegionId String No cn-hangzhou

The region ID of the instance to be associated with the Elastic IP address.

This parameter is required only after an Elastic IP address is added to a shared-bandwidth Global Acceleration instance.

InstanceType String No EcsInstance

The type of the cloud product instance to associate. Valid values:

  • Nat: NAT Gateway.
  • SlbInstance: SLB instance.
  • EcsInstance: ECS instance.
  • NetworkInterface: Secondary ENI.
Mode String No NAT

The mode of association. Valid values:

  • NAT(Default): NAT mode.
  • BINDED: Cut-through mode.
  • MULTI_BINDED: Multi-EIP to ENI mode.

This parameter is required only when the value of InstanceType is NetworkInterface.

PrivateIpAddress String No 192.xx.xx.4

An IP address in the CIDR block of the VSwitch.

If you leave the option empty, the system allocates a private IP address according to the VPC ID and VSwitch ID.

Response parameters

Parameter Type Example value Description
RequestId String C0FD0EED-F90D-4479-803D-DD62335357E5

The ID of the request.

Examples

Request example


http(s)://vpc.aliyuncs.com/? Action=AssociateEipAddress
&AllocationId=eip-2zeerraiwb7ujsxdc****
&InstanceId=i-2zebb08phyczzawe****
&<CommonParameters>

Response example

XML format

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

JSON format

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

Errors

HTTP status code Error code Error message Description
400 InvalidAssociation.Duplicated Specified instance already is associated. This instance is already associated with an Elastic IP address or a Global Acceleration instance. You must disassociate first before you can associate it with a different Elastic IP address or Global Acceleration instance.
400 OperationDenied Specified instance is not in VPC. 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 specified Elastic IP address and ECS instance are not in the same region.
400 IncorrectEipStatus Current elastic IP status does not support this operation The current status of the specified Elastic IP address does not support this operation.
404 InvalidInstanId.NotFound Specified instance does not exist. The specified instance does not exist.
400 IncorrectInstanceStatus Current instance status does not support this operation. The current instance status does not support this operation.
400 InvalidInstanceType.ValueNotSupported The specified value of InstanceType is not supported. The value of the InstanceType parameter is invalid.
400 IncorrectHaVipStatus HaVip can be operated by this action only when it's status is Available or InUse. This operation can be performed only when the HaVip is in the Available or InUse state.
400 InvalidParameter The specified parameter is not valid. The specified parameter value is invalid.
400 OperationDenied Eip of default vpc not allow this operation The Elastic IP address of the default VPC does not support this operation.
400 Forbbiden The eip instance owener error You are not authorized to operate on this Elastic IP address.
400 InvalidBindingStatus The eip binding status invalid. The associating status of the Elastic IP address is invalid.
400 BIND_INSTANCE_HAVE_PORTMAP_OR_BIND_EIP The instance may have portMap or already bind eip. You must delete the existing port forwarding rule associated with the ECS instance first.
400 BIND_INSTANCE_OWENER_ERROR Cannot operate the eip. You cannot operate on this Elastic IP address.
404 InvalidAllocationId.NotFound Specified allocation ID is not found The specified public IP address does not exist.
400 InvalidParams.NotFound instance not found The specified instance does not exist.
503 ServiceUnavailable The request has failed due to a temporary failure of the server. The request failed due to a temporary server failure.

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