Configure endpoints

Updated at:
Copy as MD

When you use the V2.0 SDK to call an OpenAPI operation, you must configure the endpoint of the target Alibaba Cloud service. When you create a resource, select the endpoint of the region that is physically closest to your business to reduce network latency and improve response speed. When you query, update, or delete a resource, select the endpoint of the region where the resource resides, because resource storage is region-specific and a cross-region operation may fail or introduce data consistency risks. This topic describes how to configure endpoints in the V2.0 SDK.

Endpoint types

Endpoints fall into two categories: public endpoints and VPC endpoints. If your business is deployed in a VPC, such as on ECS or ACK, you can access cloud resources in that VPC over a VPC endpoint. VPC endpoints improve security and reduce network latency. For more information, see Endpoints.

Set an endpoint

The V2.0 SDK provides two ways to set an endpoint: specify an endpoint, or specify a region ID to obtain the endpoint automatically.

  1. Specify an endpoint (recommended): You can specify the endpoint when you initialize the client. You can find the endpoint of a service on the product homepage of the OpenAPI Developer Portal. For more information, see the end 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 set.
        AccessKeyId = Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID"),
        // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set.
        AccessKeySecret = Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET"),
    };
    // Specify a custom endpoint.
    config.Endpoint = "dysmsapi.aliyuncs.com";
    AlibabaCloud.SDK.Dysmsapi20170525.Client client = new AlibabaCloud.SDK.Dysmsapi20170525.Client(config);
  2. Specify a RegionId: The endpoint is obtained through the addressing logic.

    image
    • If the SDK of the requested service contains a RegionId-to-endpoint mapping object and the specified RegionId exists in the object, the endpoint is obtained from the mapping object.

    • If the SDK of the requested service does not contain a RegionId-to-endpoint mapping object, or the specified RegionId does not exist in the object, the endpoint is automatically constructed based on the construction rule: ${Product ID}.${RegionId}.aliyuncs.com.

Appendix: Find an endpoint

You can find the endpoint of a cloud service in the OpenAPI portal:

  1. From the top menu of the portal, choose Products and select a product, such as ECS.

  2. On the product homepage, find the list of service regions.

  3. Select the endpoint that corresponds to your region ID, and then copy and paste it.

Alternatively, on the API debugging page, click Regions in the left-side navigation pane to view the endpoints supported by the cloud service.