Help Center/ VPC Endpoint/ API Reference/ API/ VPC Endpoint Services/ Creating a VPC Endpoint Service
Updated on 2026-11-02 GMT+08:00

Creating a VPC Endpoint Service

Function

This API is used to create a VPC endpoint service. Other users can create a VPC endpoint to connect to the endpoint service.

This is an asynchronous API. If it is successfully called, status code 200 is returned, indicating that the request has been successfully delivered. It takes 1 to 2 minutes for the system to provision a VPC endpoint service. You can query whether it has been created by referring to Querying Details of a VPC Endpoint Service.

Calling Method

For details, see Calling APIs.

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

    vpcep:endpointServices:create

    Write

    endpointServices *

    vpcep:VpceServicePrivateDnsName

    vpcep:epservices:create

    -

    vpc *

    -

    -

    • g:RequestTag/<tag-key>

    • g:TagKeys

    • g:EnterpriseProjectId

URI

POST /v1/{project_id}/vpc-endpoint-services

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Specifies the project ID. For details about how to obtain it, see Obtaining a Project ID.

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

Specifies the user token. It is a response to the API for obtaining a user token. This API is the only one that does not require authentication.The value of X-Subject-Token in the response header is the token value.

Content-Type

No

String

Specifies the MIME type of the request body. The default value application/json is recommended. For APIs used to upload objects or images, the value varies with the flow type.

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

port_id

Yes

String

Specifies the ID for identifying the backend resource of the VPC endpoint service. The ID is in universally unique identifier (UUID) format.

The value can be:

  • The port ID of the private IP address of a load balancer, if server_type is set to LB. For details, see section "Viewing the Details of a Load Balancer" in the Elastic Load Balance API Reference.

  • The network interface ID of an ECS IP address, if server_type is set to VM. For details, see the port_id field in the response parameters of section "Querying Network Interfaces of an ECS" in the Elastic Cloud Server API Reference.

Note:

  • You cannot create a VPC endpoint service in a VPC whose CIDR block overlaps with 198.19.128.0/17.

  • The destination address of a custom route in the VPC route table cannot overlap with 198.19.128.0/17.

service_name

No

String

Specifies the name of the VPC endpoint service. The name can contain a maximum of 16 characters, including letters, digits, underscores (_), and hyphens (-).

  • If you do not specify this parameter, the VPC endpoint service name is in regionName.serviceId format:

  • If you specify a valid value, the VPC endpoint service name is in the following format: regionNameserviceNameserviceId.

vpc_id

Yes

String

Specifies the ID of the VPC where the backend resource of the VPC endpoint service is located.

approval_enabled

No

Boolean

Specifies whether connection approval is required.

  • false: Connection approval is not required. The created VPC endpoint is in the accepted state.

  • true: Connection approval is required. The created VPC endpoint is in the pendingAcceptance state, and it can be used only after being approved by the user of the VPC endpoint service.

The default value is true.

service_type

No

String

Specifies the type of the VPC endpoint service.

Only your private services can be configured as interface VPC endpoint services.

There are two types of VPC endpoint services:

  • gateway: indicates gateway VPC endpoint services that are configured by the O&M personnel. You can use them directly without the need to create one yourself.

  • interface: indicates cloud services configured by the O&M personnel and private services created by yourselves.

You cannot configure these cloud services, but can use them.

You can query the public VPC endpoint services to view the VPC endpoint services that are configured by the O&M personnel and visible and accessible to all users. You can also create VPC endpoints to access gateway and interface VPC endpoint services.

server_type

Yes

String

Specifies the resource type.

  • VM: cloud server

  • LB: a load balancer that works well for high-traffic services that require high reliability and disaster recovery

ip

No

String

Specifies the IPv4 address or domain name of the interface VPC endpoint in VLAN scenarios.

ports

Yes

Array of PortList objects

Specifies the port mappings available for the VPC endpoint service.

Each port mapping must be unique for the same VPC endpoint service. If multiple VPC endpoint services share the same port ID, the value combinations of server_port and protocol of each of these VPC endpoint services must be unique.

A maximum of 200 port mappings can be added at a time.

tcp_proxy

No

String

Definition

Specifies whether to transfer client information, such as the source IP address, source port, and marker ID, to the server.

Constraints

The information can be sent to the server in the following ways:

  • TCP TOA: The client information is placed into the TCP Options field and sent to the server. TCP TOA is available only when the backend resource is OBS.

  • Proxy Protocol: The client information is placed into the tcp payload field and sent to the server. This parameter is available only when the server can parse the tcp payload field.

Range

  • close: Neither TCP TOA nor Proxy Protocol is enabled.

  • proxy_open: Proxy Protocol is enabled.

Default Value

close

NOTE:
The TCP Options field does not have the anti-tampering protection. Intermediate network devices can modify this field during data transmission.

tags

No

Array of TagList objects

Lists the resource tags. A maximum of 20 tags can be added to each VPC endpoint service.

description

No

String

Specifies the description field. The value can contain characters such as letters and digits, but cannot contain angle brackets ().

ip_version

No

String

Specifies the IP version of the VPC endpoint service. Only professional VPC endpoint services support this parameter.

  • ipv4: The IP address of the VPC endpoint service must be an IPv4 address.

  • ipv6: The IP address of the VPC endpoint service must be an IPv6 address.

snat_network_id

No

String

Specifies the SNAT network ID of the interface VPC endpoint service. This parameter is mandatory when ip_version is set to ipv6. Select the ID of any network in the VPC configured for the VPC endpoint service. This parameter is used when the service type is VM or ELBv2.

Table 4 PortList

Parameter

Mandatory

Type

Description

client_port

No

Integer

Specifies the port to be accessed by a VPC endpoint.

This port is provided by the VPC endpoint, allowing you to access the VPC endpoint service. Supported range: 1 to 65535.

server_port

No

Integer

Specifies the port for accessing the VPC endpoint service.

This port is associated with backend resources to provide VPC endpoint services. Supported range: 1 to 65535

protocol

No

String

Port mapping protocol. TCP is supported.

Table 5 TagList

Parameter

Mandatory

Type

Description

key

No

String

Specifies the tag key.

key cannot be left blank. A key can contain 1 to 128 characters.

A key can contain UTF-8 letters, digits, spaces, and the following special characters _ . : = + - @

Keys cannot start with _sys_ because it indicates a system tag.

A key cannot start or end with a space.

value

No

String

Specifies the tag value.

A value can contain 0 to 255 characters.

A value can contain UTF-8 letters, digits, spaces, and the following special characters _ . : / = + - @

A value can be an empty string.

Response Parameters

Status code: 200

Table 6 Response body parameters

Parameter

Type

Description

id

String

Specifies the unique ID of the VPC endpoint service.

port_id

String

Specifies the ID for identifying the backend resource of the VPC endpoint service. The ID is in universally unique identifier (UUID) format.

The value can be:

  • The port ID of the private IP address of a load balancer, if server_type is set to LB.

  • The network interface ID of an ECS IP address, if server_type is set to VM.

service_name

String

Specifies the name of the VPC endpoint service.

server_type

String

Specifies the resource type.

  • VM: cloud server

  • LB: enhanced load balancer

vpc_id

String

Specifies the ID of the VPC where the backend resource of the VPC endpoint service is located.

pool_id

String

Specifies the cluster ID of the VPC endpoint service.

approval_enabled

Boolean

Specifies whether connection approval is required.

  • false: Connection approval is not required. The created VPC endpoint is in the accepted state.

  • true: Connection approval is required. The created VPC endpoint is in the pendingAcceptance state, and it can be used only after being approved by the user of the VPC endpoint service.

status

String

Specifies the status of the VPC endpoint service.

  • creating: The VPC endpoint service is being created.

  • available: The VPC endpoint service is connectable.

  • failed: The VPC endpoint service failed to be created.

service_type

String

Specifies the type of the VPC endpoint service.

There are two types of VPC endpoint services: interface and gateway.

  • gateway: indicates the VPC endpoint services that are configured by the O&M personnel. You can use them directly without creating them by yourselves.

  • interface: indicates the cloud services configured by the O&M personnel and private services created by yourselves.

You cannot configure these cloud services, but can use them.

You can create VPC endpoints to connect to gateway and interface VPC endpoint services.

created_at

String

Specifies when the VPC endpoint service was created.

The UTC time format YYYY-MM-DDTHH:MM:SSZ is used.

updated_at

String

Specifies when the VPC endpoint service was updated.

The UTC time format YYYY-MM-DDTHH:MM:SSZ is used.

project_id

String

Specifies the project ID.

ip

String

Specifies the IPv4 address or domain name of the interface VPC endpoint in VLAN scenarios.

ports

Array of PortList objects

Specifies the port mappings available for the VPC endpoint service.

Each port mapping must be unique for the same VPC endpoint service. If multiple VPC endpoint services share the same port ID, the value combinations of server_port and protocol of each of these VPC endpoint services must be unique.

tcp_proxy

String

Definition

Specifies whether to transfer client information, such as source IP address, source port, and marker ID, to the server.

Range

  • close: Neither TCP TOA nor Proxy Protocol is enabled.

  • proxy_open: Proxy Protocol is enabled.

tags

Array of TagList objects

Specifies resource tags.

description

String

Specifies the description field. The value can contain characters such as letters and digits, but cannot contain angle brackets (< or >).

enable_policy

Boolean

Specifies whether the VPC endpoint policy can be customized.

  • false: The VPC endpoint policy cannot be customized.

  • true: The VPC endpoint policy can be customized.

The default value is false.

ip_version

String

Specifies the IP version of the VPC endpoint service. Only professional VPC endpoint services support this parameter.

  • ipv4: The IP address of the VPC endpoint service must be an IPv4 address.

  • ipv6: The IP address of the VPC endpoint service must be an IPv6 address.

Table 7 PortList

Parameter

Type

Description

client_port

Integer

Specifies the port to be accessed by a VPC endpoint.

This port is provided by the VPC endpoint, allowing you to access the VPC endpoint service. Supported range: 1 to 65535.

server_port

Integer

Specifies the port for accessing the VPC endpoint service.

This port is associated with backend resources to provide VPC endpoint services. Supported range: 1 to 65535

protocol

String

Port mapping protocol. TCP is supported.

Table 8 TagList

Parameter

Type

Description

key

String

Specifies the tag key.

key cannot be left blank. A key can contain 1 to 128 characters.

A key can contain UTF-8 letters, digits, spaces, and the following special characters _ . : = + - @

Keys cannot start with _sys_ because it indicates a system tag.

A key cannot start or end with a space.

value

String

Specifies the tag value.

A value can contain 0 to 255 characters.

A value can contain UTF-8 letters, digits, spaces, and the following special characters _ . : / = + - @

A value can be an empty string.

Example Requests

Creating an interface VPC endpoint service and setting approval_enabled to false, service type to VM, client_port to 8080 and 8081, server_port to 90 and 80, and protocol to TCP

POST https://{endpoint}/v1/{project_id}/vpc-endpoint-services

{
  "port_id" : "4189d3c2-8882-4871-a3c2-d380272eed88",
  "vpc_id" : "4189d3c2-8882-4871-a3c2-d380272eed80",
  "approval_enabled" : false,
  "service_type" : "interface",
  "server_type" : "VM",
  "ports" : [ {
    "client_port" : 8080,
    "server_port" : 90,
    "protocol" : "TCP"
  }, {
    "client_port" : 8081,
    "server_port" : 80,
    "protocol" : "TCP"
  } ]
}

Example Responses

Status code: 200

{
  "id" : "4189d3c2-8882-4871-a3c2-d380272eed83",
  "port_id" : "4189d3c2-8882-4871-a3c2-d380272eed88",
  "vpc_id" : "4189d3c2-8882-4871-a3c2-d380272eed80",
  "pool_id" : "5289d3c2-8882-4871-a3c2-d380272eed80",
  "status" : "available",
  "approval_enabled" : false,
  "service_name" : "test123",
  "service_type" : "interface",
  "server_type" : "VM",
  "project_id" : "6e9dfd51d1124e8d8498dce894923a0d",
  "created_at" : "2022-04-14T09:35:47Z",
  "ports" : [ {
    "client_port" : 8080,
    "server_port" : 90,
    "protocol" : "TCP"
  }, {
    "client_port" : 8081,
    "server_port" : 80,
    "protocol" : "TCP"
  } ]
}

SDK Sample Code

The SDK sample code is as follows.

Creating an interface VPC endpoint service and setting approval_enabled to false, service type to VM, client_port to 8080 and 8081, server_port to 90 and 80, and protocol to TCP

 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
58
59
60
61
62
63
64
65
66
67
68
69
70
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.vpcep.v1.region.VpcepRegion;
import com.huaweicloud.sdk.vpcep.v1.*;
import com.huaweicloud.sdk.vpcep.v1.model.*;

import java.util.List;
import java.util.ArrayList;

public class CreateEndpointServiceSolution {

    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);

        VpcepClient client = VpcepClient.newBuilder()
                .withCredential(auth)
                .withRegion(VpcepRegion.valueOf("<YOUR REGION>"))
                .build();
        CreateEndpointServiceRequest request = new CreateEndpointServiceRequest();
        CreateEndpointServiceRequestBody body = new CreateEndpointServiceRequestBody();
        List<PortList> listbodyPorts = new ArrayList<>();
        listbodyPorts.add(
            new PortList()
                .withClientPort(8080)
                .withServerPort(90)
                .withProtocol(PortList.ProtocolEnum.fromValue("TCP"))
        );
        listbodyPorts.add(
            new PortList()
                .withClientPort(8081)
                .withServerPort(80)
                .withProtocol(PortList.ProtocolEnum.fromValue("TCP"))
        );
        body.withPorts(listbodyPorts);
        body.withServerType(CreateEndpointServiceRequestBody.CreateEndpointServiceRequestBody.fromValue("VM"));
        body.withServiceType(CreateEndpointServiceRequestBody.CreateEndpointServiceRequestBody.fromValue("interface"));
        body.withApprovalEnabled(false);
        body.withVpcId("4189d3c2-8882-4871-a3c2-d380272eed80");
        body.withPortId("4189d3c2-8882-4871-a3c2-d380272eed88");
        request.withBody(body);
        try {
            CreateEndpointServiceResponse response = client.createEndpointService(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());
        }
    }
}

Creating an interface VPC endpoint service and setting approval_enabled to false, service type to VM, client_port to 8080 and 8081, server_port to 90 and 80, and protocol to TCP

 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
# coding: utf-8

import os
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkvpcep.v1.region.vpcep_region import VpcepRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkvpcep.v1 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 = VpcepClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(VpcepRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = CreateEndpointServiceRequest()
        listPortsbody = [
            PortList(
                client_port=8080,
                server_port=90,
                protocol="TCP"
            ),
            PortList(
                client_port=8081,
                server_port=80,
                protocol="TCP"
            )
        ]
        request.body = CreateEndpointServiceRequestBody(
            ports=listPortsbody,
            server_type="VM",
            service_type="interface",
            approval_enabled=False,
            vpc_id="4189d3c2-8882-4871-a3c2-d380272eed80",
            port_id="4189d3c2-8882-4871-a3c2-d380272eed88"
        )
        response = client.create_endpoint_service(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

Creating an interface VPC endpoint service and setting approval_enabled to false, service type to VM, client_port to 8080 and 8081, server_port to 90 and 80, and protocol to TCP

 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    vpcep "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/vpcep/v1"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/vpcep/v1/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/vpcep/v1/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 := vpcep.VpcepClientBuilder().
         WithRegion(region.ValueOf("<YOUR REGION>")).
         WithCredential(auth).
         SafeBuild()


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

    client := vpcep.NewVpcepClient(hcClient)

    request := &model.CreateEndpointServiceRequest{}
	clientPortPorts:= int32(8080)
	serverPortPorts:= int32(90)
	protocolPorts:= model.GetPortListProtocolEnum().TCP
	clientPortPorts1:= int32(8081)
	serverPortPorts1:= int32(80)
	protocolPorts1:= model.GetPortListProtocolEnum().TCP
	var listPortsbody = []model.PortList{
        {
            ClientPort: &clientPortPorts,
            ServerPort: &serverPortPorts,
            Protocol: &protocolPorts,
        },
        {
            ClientPort: &clientPortPorts1,
            ServerPort: &serverPortPorts1,
            Protocol: &protocolPorts1,
        },
    }
	serviceTypeCreateEndpointServiceRequestBody:= model.GetCreateEndpointServiceRequestBodyServiceTypeEnum().INTERFACE
	approvalEnabledCreateEndpointServiceRequestBody:= false
	request.Body = &model.CreateEndpointServiceRequestBody{
		Ports: listPortsbody,
		ServerType: model.GetCreateEndpointServiceRequestBodyServerTypeEnum().VM,
		ServiceType: &serviceTypeCreateEndpointServiceRequestBody,
		ApprovalEnabled: &approvalEnabledCreateEndpointServiceRequestBody,
		VpcId: "4189d3c2-8882-4871-a3c2-d380272eed80",
		PortId: "4189d3c2-8882-4871-a3c2-d380272eed88",
	}
	response, err := client.CreateEndpointService(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

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

The server has successfully processed the request.

Error Codes

See Error Codes.