Configure an endpoint

Updated at:
Copy as MD

Configure service endpoints in Alibaba Cloud SDK V2.0 for Python by specifying a custom endpoint or a region ID.

An endpoint is a domain name of an Alibaba Cloud service, such as ecs.cn-hangzhou.aliyuncs.com.

Configuration methods

The SDK supports two endpoint configuration methods, listed by descending priority:

Note

Prefer a custom endpoint.

  1. Specify a custom endpoint: Set the endpoint when you initialize the client. Find service endpoints on the product page in OpenAPI Explorer, or follow the steps in the appendix.

    from alibabacloud_tea_openapi.models import Config
    
    config = Config(
        # Configure the credential.
        endpoint='<endpoint>'  # endpoint
    )
    
  2. Specify a region ID:

    • If the SDK contains a region-to-endpoint map for the service and the specified region ID exists in it, the SDK retrieves the corresponding endpoint.

    • If the map is missing or does not contain the specified region ID, the SDK constructs the endpoint automatically using a naming convention.

    from alibabacloud_tea_openapi.models import Config
    
    config = Config(
        # Configure the credential.
        region_id='cn-hangzhou',  # Specify an endpoint based on the region ID.
    )
    

VPC endpoint use cases

Use a VPC endpoint in these scenarios:

  • Your business runs in both on-premises data centers and the cloud, with VPC-isolated modules connected over the public internet.

  • You connect a VPC-based cloud data center to your on-premises environment through Express Connect for hybrid cloud scenarios such as data security, burst capacity, and fast data synchronization.

  • Multiple applications in a VPC with different peak hours share bandwidth across IP addresses to smooth traffic and reduce costs.

  • Your services run entirely in VPCs across multiple nodes and require high-speed connections between them for geographically distributed users.

Authentication endpoint

Some API operations accept a custom open platform endpoint. If omitted, the SDK uses the default public endpoint. Internally, the SDK calls a file upload authentication service to obtain upload credentials and default OSS instance information.

  • Configure a VPC endpoint to request file upload authentication information over a VPC.

from alibabacloud_tea_openapi.models import Config
from alibabacloud_tea_util.models import RuntimeOptions

from alibabacloud_facebody20191230.models import DetectBodyCountAdvanceRequest
from alibabacloud_facebody20191230.client import Client

runtime = RuntimeOptions()
config = Config(
    # Configure the credential.
    region_id='cn-hangzhou',
    # The endpoint that is used for authentication.
    open_platform_endpoint='openplatform-vpc.cn-shanghai.aliyuncs.com'
)

client = Client(config)
with open('test.txt', 'rb') as f:
    request = DetectBodyCountAdvanceRequest(image_urlobject=f)
    response = client.detect_body_count_advance(request, runtime)
    # The response, which contains the body and headers that are returned by the server side.
    print(response.body)
    print(response.headers)
  • Configure a VPC endpoint to request file upload authentication information over an internal network or VPC.

from alibabacloud_tea_openapi.models import Config
from alibabacloud_tea_util.models import RuntimeOptions

from alibabacloud_facebody20191230.models import DetectBodyCountAdvanceRequest
from alibabacloud_facebody20191230.client import Client

runtime = RuntimeOptions()
config = Config(
    # Configure the credential.
    region_id='cn-hangzhou',
    open_platform_endpoint='openplatform-vpc.cn-shanghai.aliyuncs.com',
    endpoint_type='internal' # Configure the Object Storage Service (OSS) endpoint that you want to use to upload the file.
)

client = Client(config)
with open('test.txt', 'rb') as f:
    request = DetectBodyCountAdvanceRequest(image_urlobject=f)
    response = client.detect_body_count_advance(request, runtime)
    # The response, which contains the body and headers that are returned by the server side.
    print(response.body)
    print(response.headers)

Appendix: Find an endpoint

Find service endpoints in OpenAPI Explorer:

  1. From the top menu, select Products, and then choose a service such as ECS.

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

3. Select the endpoint for your region ID, then copy and paste it.

Alternatively, on the API Debugging page, click Regions in the left-side navigation pane to view available endpoints.