Updated on 2026-11-16 GMT+08:00

Binding an EIP

Function

This API is used to bind an EIP.

Authorization Information

Each account has all the permissions required to call all APIs, but IAM users must be assigned the required permissions.

  • If you are using role/policy-based authorization, see Permissions Policies and Supported Actions for details on the required permissions.
  • If you are using identity policy-based authorization, the following identity policy-based permissions are required.

    Action

    Access Level

    Resource Type (*: required)

    Condition Key

    Alias

    Dependencies

    eip:publicIps:associateInstance

    Write

    publicip *

    • g:EnterpriseProjectId

    • g:ResourceTag/<tag-key>

    vpc:publicIps:update

    -

URI

POST /v3/{project_id}/eip/publicips/{publicip_id}/associate-instance

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Maximum: 32

publicip_id

Yes

String

EIP ID

Minimum: 36

Maximum: 36

Request Parameters

Table 2 Request body parameters

Parameter

Mandatory

Type

Description

publicip

Yes

AssociatePublicipsOption object

EIP object.

Table 3 AssociatePublicipsOption

Parameter

Mandatory

Type

Description

associate_instance_type

Yes

String

  • Definition: Type of the instance that the port belongs to

  • Range:

    • PORT (Instance type, including ECS, BMS, and CCE)

    • NATGW (NAT gateway type)

    • ELB (Load balancer type)

    • ELBV1 (ELB V1 load balancer type)

    • VPN (VPN instance type)

  • Constraints:

    • If both associate_instance_type and associate_instance_id are not left empty, the EIP is bound to an instance.

    • associate_instance_type cannot be left empty.

Minimum: 0

Maximum: 36

associate_instance_id

Yes

String

  • Definition: ID of the bound instance, such as a load balancer ID or an ECS network interface ID.

  • Constraints:

    • If both associate_instance_type and associate_instance_id are not left empty, the EIP is bound to an instance.

    • associate_instance_id cannot be left empty.

Minimum: 0

Maximum: 36

Response Parameters

Status code: 200

Table 4 Response body parameters

Parameter

Type

Description

request_id

String

Request ID.

publicip

PublicipInstanceResp object

Response body of binding an EIP

Table 5 PublicipInstanceResp

Parameter

Type

Description

id

String

  • Definition: EIP ID, which uniquely identifies the EIP.

project_id

String

  • Definition: Project ID.

ip_version

Integer

  • Definition: IP address version.

  • Range:

    • 4: IPv4 EIP

    • 6: IPv6 EIP

public_ip_address

String

  • Definition: EIP

public_ipv6_address

String

  • Definition: IPv6 EIP. This parameter does not display when you assign an IPv4 EIP.

status

String

  • Definition: EIP status

  • Range:

    • FREEZED: frozen

    • BIND_ERROR: failed to be bound

    • BINDING: being bound

    • PENDING_DELETE: being released

    • PENDING_CREATE: being assigned

    • NOTIFYING: being assigned

    • NOTIFY_DELETE: being released

    • PENDING_UPDATE: being updated

    • DOWN: not bound

    • ACTIVE: bound

    • ELB: bound to a load balancer

    • VPN: bound to a VPN

    • ERROR: failed

description

String

  • Definition: Supplementary information about the EIP.

  • Constraints: You can customize this value to identify your EIP, which is not perceived by the system.

public_border_group

String

  • Definition: Whether the resource is in a central region or an edge site.

  • Range: The value can be center or an edge site name.

created_at

String

  • Definition: Time (UTC) when the resource was created.

  • Format: yyyy-MM-ddTHH:mm:ssZ

updated_at

String

  • Definition: Time (UTC) when the resource was updated.

  • Format: yyyy-MM-ddTHH:mm:ssZ

type

String

  • Definition: EIP type.

  • Constraints: N/A

  • Range:

    • EIP: IPv4 EIP.

    • DUALSTACK: IPv6 EIP.

  • Default Value: N/A

vnic

VnicInfo object

  • Definition: Port information of the instance that an EIP is bound to.

  • Constraints: If the instance has no port, the value is null.

bandwidth

PublicipBandwidthInfo object

  • Definition: Bandwidth of an EIP

enterprise_project_id

String

  • Definition: Enterprise project ID The value is 0 or a string that contains a maximum of 36 characters in the UUID format with hyphens (-). This is the ID of the enterprise project that you associate with the EIP when you assign the EIP.

billing_info

String

  • Definition: Order information of an EIP.

  • Constraints: Order information is available only for yearly/monthly resources. This parameter is left empty for pay-per-use resources.

lock_status

String

  • Definition: Frozen reason of the EIP.

  • Constraints: The metadata type is used.

  • Range:

    • POLICE: frozen due to public security issues

    • LOCKED: frozen due to common issues

    • ARREAR: frozen due to arrears

    • DELABLE: frozen and can be deleted

  • Default Value: N/A

associate_instance_type

String

  • Definition: Type of the instance with an EIP bound.

  • Range:

    • PORT (Instance type, including ECS, BMS, and CCE)

    • NATGW (NAT gateway type)

    • ELB (Load balancer type)

    • VPN (VPN instance type)

    - ELBV1 (ELB V1 load balancer type)

associate_instance_id

String

  • Definition: ID of the instance with an EIP bound.

publicip_pool_id

String

  • Definition: ID of the network that an EIP belongs to. It is the network ID corresponding to publicip_pool_name.

publicip_pool_name

String

  • Definition: Network type of an EIP, including common EIP pool, for example, 5_bgp and dedicated EIP pool.

  • For details about a dedicated EIP pool, see the APIs about publicip_pool.

alias

String

  • Definition: EIP name

Table 6 VnicInfo

Parameter

Type

Description

private_ip_address

String

Definition

Private IP address.

Range

N/A

device_id

String

Definition

ID of the device that the port belongs to. The device ID indicates the ID of the cloud service resource that uses the private IP address in the subnet, for example, the cloud server ID or load balancer ID. The system automatically sets this parameter.

Range

N/A

device_owner

String

Definition

Device that the port belongs to. It can be a cloud service resource that uses a private IP address in the subnet.

Range

  • network:dhcp: DHCP service

  • network:VIP_PORT: Virtual IP address

  • network:router_interface_distributed: Subnet gateway address

  • network:router_centralized_snat: SNAT gateway address

vpc_id

String

Definition

VPC ID.

Range

N/A

port_id

String

Definition

Port ID.

Range

N/A

port_profile

String

Definition

Port profile.

Range

N/A

mac

String

Definition

MAC address of the port.

Range

The system automatically sets this parameter.

vtep

String

Definition

VTEP IP address.

Range

N/A

vni

String

Definition

VXLAN ID.

Range

N/A

instance_id

String

Definition

The ID of the instance that the port belongs to, for example, RDS instance ID.

Range

The system automatically sets this parameter.

instance_type

String

Definition

Type of the instance that uses the port.

Range

  • PORT: elastic network interface

  • PEP_PORT: PEP elastic network interface

  • EVPN: Ethernet virtual private network

  • NATGW: NAT gateway

  • P2CVPN: P2C virtual private network

port_vif_details

String

Definition

Details about the virtual interface of the network interface.

Range

N/A

Table 7 PublicipBandwidthInfo

Parameter

Type

Description

id

String

Definition

Bandwidth ID.

Range

N/A

size

Integer

Definition

Bandwidth size.

Range

The value ranges from 5 Mbit/s to 2000 Mbit/s.

share_type

String

Definition

Whether the bandwidth is shared or dedicated.

Range

  • PER: dedicated bandwidth

  • WHOLE: shared bandwidth

charge_mode

String

Definition

The billing option of the bandwidth.

Range

  • bandwidth: billed by bandwidth

  • traffic: billed by traffic

  • 95peak_plus: billed by enhanced 95th percentile bandwidth

name

String

Definition

Bandwidth name.

Range

The value can contain 1 to 64 characters, including letters, digits, underscores (_), hyphens (-), and periods (.).

billing_info

String

Definition

Bill information. If billing_info is specified, the bandwidth is billed on a yearly/monthly basis.

Range

N/A

Example Requests

Bind an EIP to an instance. The instance IP address and instance type are required.

POST /v3/{project_id}/eip/publicips/{publicip_id}/associate-instance

{
  "publicip" : {
    "associate_instance_id" : "921b9dc7-8151-41e1-b83c-d50fe959592a",
    "associate_instance_type" : "PORT"
  }
}

Example Responses

Status code: 200

  • {
      "publicip" : {
        "alias" : "abcd",
        "associate_instance_id" : "921b9dc7-8151-41e1-b83c-d50fe959592a",
        "associate_instance_type" : "PORT",
        "bandwidth" : {
          "billing_info" : "xxxx:xxxx:xxxx:xxxx",
          "charge_mode" : "bandwidth",
          "id" : "80549ae1-cf7a-4f39-a45f-bdb8e194a1f4",
          "name" : "bandwidth-bd25-test",
          "share_type" : "WHOLE",
          "size" : 7
        },
        "billing_info" : null,
        "created_at" : "2020-06-18T14:05:32Z",
        "description" : "test!!!!",
        "enterprise_project_id" : "0",
        "public_border_group" : "center",
        "id" : "b0c42aa6-3d1d-4b39-9188-35ee6aa8d6f7",
        "ip_version" : 4,
        "lock_status" : null,
        "project_id" : "060576782980d5762f9ec014dd2f1148",
        "public_ip_address" : "xx.xx.xx.xx",
        "public_ipv6_address" : null,
        "publicip_pool_id" : "160576782980d5762f9ec014dd2f1148",
        "publicip_pool_name" : "5_mobile",
        "status" : "ACTIVE",
        "type" : "EIP",
        "updated_at" : "2020-06-18T14:05:32Z",
        "vnic" : {
          "device_id" : "78aa6d7f-7111-434e-9a93-0dc6fdacff63",
          "device_owner" : "network:nat_gateway",
          "instance_id" : "",
          "instance_type" : "",
          "mac" : "fa:16:3e:83:6b:0a",
          "port_id" : "921b9dc7-8151-41e1-b83c-d50fe959592a",
          "port_profile" : null,
          "private_ip_address" : "xx.xx.xx.xx",
          "vni" : null,
          "vpc_id" : "a26c231a-cf6f-48d3-83db-1e261d0e235a",
          "vtep" : null,
          "port_vif_details" : "{\"primary_interface\": true}"
        }
      },
      "request_id" : "ead9f912bd1191e3d5f0037141098d91"
    }

SDK Sample Code

The SDK sample code is as follows.

Java

Bind an EIP to an instance. The instance IP address and instance type are required.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package com.huaweicloud.sdk.test;

import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.auth.BasicCredentials;
import com.huaweicloud.sdk.core.exception.ConnectionException;
import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
import com.huaweicloud.sdk.core.exception.ServiceResponseException;
import com.huaweicloud.sdk.eip.v3.region.EipRegion;
import com.huaweicloud.sdk.eip.v3.*;
import com.huaweicloud.sdk.eip.v3.model.*;


public class AssociatePublicipsSolution {

    public static void main(String[] args) {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        String ak = System.getenv("CLOUD_SDK_AK");
        String sk = System.getenv("CLOUD_SDK_SK");
        String projectId = "{project_id}";

        ICredential auth = new BasicCredentials()
                .withProjectId(projectId)
                .withAk(ak)
                .withSk(sk);

        EipClient client = EipClient.newBuilder()
                .withCredential(auth)
                .withRegion(EipRegion.valueOf("<YOUR REGION>"))
                .build();
        AssociatePublicipsRequest request = new AssociatePublicipsRequest();
        request.withPublicipId("{publicip_id}");
        AssociatePublicipsRequestBody body = new AssociatePublicipsRequestBody();
        AssociatePublicipsOption publicipbody = new AssociatePublicipsOption();
        publicipbody.withAssociateInstanceType(AssociatePublicipsOption.AssociateInstanceTypeEnum.fromValue("PORT"))
            .withAssociateInstanceId("921b9dc7-8151-41e1-b83c-d50fe959592a");
        body.withPublicip(publicipbody);
        request.withBody(body);
        try {
            AssociatePublicipsResponse response = client.associatePublicips(request);
            System.out.println(response.toString());
        } catch (ConnectionException e) {
            e.printStackTrace();
        } catch (RequestTimeoutException e) {
            e.printStackTrace();
        } catch (ServiceResponseException e) {
            e.printStackTrace();
            System.out.println(e.getHttpStatusCode());
            System.out.println(e.getRequestId());
            System.out.println(e.getErrorCode());
            System.out.println(e.getErrorMsg());
        }
    }
}

Python

Bind an EIP to an instance. The instance IP address and instance type are required.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# coding: utf-8

import os
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkeip.v3.region.eip_region import EipRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkeip.v3 import *

if __name__ == "__main__":
    # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak = os.environ["CLOUD_SDK_AK"]
    sk = os.environ["CLOUD_SDK_SK"]
    projectId = "{project_id}"

    credentials = BasicCredentials(ak, sk, projectId)

    client = EipClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(EipRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = AssociatePublicipsRequest()
        request.publicip_id = "{publicip_id}"
        publicipbody = AssociatePublicipsOption(
            associate_instance_type="PORT",
            associate_instance_id="921b9dc7-8151-41e1-b83c-d50fe959592a"
        )
        request.body = AssociatePublicipsRequestBody(
            publicip=publicipbody
        )
        response = client.associate_publicips(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

Go

Bind an EIP to an instance. The instance IP address and instance type are required.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    eip "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/eip/v3"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/eip/v3/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/eip/v3/region"
)

func main() {
    // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak := os.Getenv("CLOUD_SDK_AK")
    sk := os.Getenv("CLOUD_SDK_SK")
    projectId := "{project_id}"

    auth, err := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        WithProjectId(projectId).
        SafeBuild()

    if err != nil {
        fmt.Println(err)
        return
    }

    hcClient, err := eip.EipClientBuilder().
         WithRegion(region.ValueOf("<YOUR REGION>")).
         WithCredential(auth).
         SafeBuild()


    if err != nil {
        fmt.Println(err)
        return
    }

    client := eip.NewEipClient(hcClient)

    request := &model.AssociatePublicipsRequest{}
	request.PublicipId = "{publicip_id}"
	publicipbody := &model.AssociatePublicipsOption{
		AssociateInstanceType: model.GetAssociatePublicipsOptionAssociateInstanceTypeEnum().PORT,
		AssociateInstanceId: "921b9dc7-8151-41e1-b83c-d50fe959592a",
	}
	request.Body = &model.AssociatePublicipsRequestBody{
		Publicip: publicipbody,
	}
	response, err := client.AssociatePublicips(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

More

For SDK sample code of more programming languages, see the Sample Code tab in API Explorer. SDK sample code can be automatically generated.

Status Codes

Status Code

Description

200

Normal response to the POST operation

Error Codes

See Error Codes.