Elastic Algorithm Service (EAS) allows you to call a service over the virtual private cloud (VPC) direct connection channel by using the official SDK for Python or custom call logic. This topic describes these call methods in detail.
How it works

Prerequisites
- A dedicated resource group is purchased. You can enable the VPC direct connection channel feature only for services that are deployed in dedicated resource groups. For more information, see Activation and purchase.
- The VPC direct connection channel feature is enabled for the dedicated resource group before you deploy a service. For more information, see VPC direct connection channel.
Call methods
- Use the official SDK for Python
EAS encapsulates the call logic and provides the official SDK for Python. You can use this SDK to call services over the VPC direct connection channel.
- Use custom call logic
We recommend that you use the official SDK to call services. This reduces the time that is required for defining call logic and improves the call stability. If you need to use other languages or custom call logic, you can follow the method that is provided in the Use custom call logic section. To implement the custom call logic, you must construct service requests based on specific frameworks. For more information, see Construct requests based on a universal processor.
Use the official SDK for Python
- Install the SDK.
For more information about how to use the SDK for Python, visit GitHub.pip install -U eas-prediction --user
- Compile a call program.
Take a program that uses strings as input and output as an example. For information about sample programs with other input and output formats, such as TensorFlow and PyTorch programs, visit GitHub.
The input of the#!/usr/bin/env python from eas_prediction import PredictClient from eas_prediction import StringRequest from eas_prediction import TFRequest from eas_prediction import ENDPOINT_TYPE_DIRECT if __name__ == '__main__': client = PredictClient('http://pai-eas-vpc.cn-shanghai.aliyuncs.com', 'mnist_saved_model_example') client.set_token('M2FhNjJlZDBmMzBmMzE4NjFiNzZhMmUxY2IxZjkyMDczNzAzYjFi****') client.set_endpoint_type(ENDPOINT_TYPE_DIRECT) # Indicates that the service is accessed over a VPC direct connection channel. client.init() #request = StringRequest('[{}]') req = TFRequest('predict_images') req.add_feed('images', [1, 784], TFRequest.DT_FLOAT, [1] * 784) for x in range(0, 1000000): resp = client.predict(req) print(resp)
client = PredictClient()
function is the VPC endpoint that is used to call the service. For example, if the VPC endpoint is http://166408185518****.vpc.cn-hangzhou.pai-eas.aliyuncs.com/api/predict/heart_predict_online, the format that is used to call thePredictClient()
function isclient = PredictClient('http://166408185518****.vpc.cn-hangzhou.pai-eas.aliyuncs.com','heart_predict_online')
.
Use custom call logic
Region | URL |
---|---|
China (Shanghai) | http://pai-eas-vpc.cn-shanghai.aliyuncs.com/exported/apis/eas.alibaba-inc.k8s.io/v1/upstreams/ |
China (Beijing) | http://pai-eas-vpc.cn-beijing.aliyuncs.com/exported/apis/eas.alibaba-inc.k8s.io/v1/upstreams/ |
China (Hangzhou) | http://pai-eas-vpc.cn-hangzhou.aliyuncs.com/exported/apis/eas.alibaba-inc.k8s.io/v1/upstreams/ |
%mnist_saved_model_example;
service in the China (Hangzhou) region. This service has two instances. $curl http://pai-eas-vpc.cn-shanghai.aliyuncs.com/exported/apis/eas.alibaba-inc.k8s.io/v1/upstreams/mnist_saved_model_example
The following code provides an example on the obtained backend addresses of the service:
{ "correlative": [ "mnist_saved_model_example" ], "endpoints": { "items": [ { "app": "mnist-saved-model-example", "ip": "172.16.XX.XX", "port": 50000, "weight": 100 }, { "app": "mnist-saved-model-example", "ip": "172.16.XX.XX", "port": 50000, "weight": 100 } ] } }As shown in the preceding code, the client can obtain the IP addresses, port numbers, and weights of the two backend instances of the service. You can use the weighted round robin (WRR) algorithm to obtain the information of an instance and access the instance over the VPC direct connection channel before each service call.