All Products
Search
Document Center

Alibaba Cloud SDK:Configure an endpoint

Last Updated:Dec 12, 2024

An endpoint is a domain name of an Alibaba Cloud service. For example, the endpoint of Elastic Compute Service (ECS) in the China (Hangzhou) region is ecs.cn-hangzhou.aliyuncs.com. Each Alibaba Cloud service has its unique endpoints. The endpoints of a service may vary based on regions. This topic describes how to configure an endpoint in Alibaba Cloud SDK V2.0.

Endpoint type

Endpoints are divided into public endpoints and Virtual Private Cloud (VPC) endpoints. For more information, see Endpoints.

Configure an endpoint

Alibaba Cloud SDK V2.0 provides two methods for configuring an endpoint. The following section describes the methods based on their priority in descending order.

Note

We recommend that you configure an endpoint by specifying a custom endpoint.

  1. Specify a custom endpoint. You can specify an endpoint when you initialize a client. You can query an endpoint in OpenAPI Portal. For more information, see the "Appendix: Query an endpoint" section of this topic.

    AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config
    {
        // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is configured in the code runtime environment. 
        AccessKeyId = Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID"),
        // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is configured in the code runtime environment. 
        AccessKeySecret = Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET"),
    };
    // Specify an endpoint.
    config.Endpoint = "dysmsapi.aliyuncs.com";
    AlibabaCloud.SDK.Dysmsapi20170525.Client client = new AlibabaCloud.SDK.Dysmsapi20170525.Client(config);
  2. Specify a region ID: You can query an endpoint by using the endpoint data file.

    image
    • If the SDK for an Alibaba Cloud service contains the mapping relationship object of region IDs and endpoints and the specified region ID is included in the relationship object, you can obtain an endpoint from the mapping relationship object.

    • If the SDK of an Alibaba Cloud service does not contain the mapping relationship object of region IDs and endpoints or the specified region ID is not included in the mapping relationship object, an endpoint is automatically concatenated based on concatenation rules. Concatenating format: ${Service ID}.${RegionId}.aliyuncs.com.

Appendix: Query an endpoint

You can query an endpoint in OpenAPI Explorer.

  1. Select an Alibaba Cloud service on the homepage of OpenAPI Explorer. In this example, ECS is selected.

image.png

2. On the homepage of ECS, click the Regions tab.

image.png

3. Find the region that you want to specify and copy the endpoint of ECS in the region.

You can also query the endpoints of ECS on the Debugging page. On this page, move the pointer over Regions in the left-side navigation pane to view the endpoints of ECS.

image