Configuration
When you use the software development kit (SDK) to access the Cloud Managed Network service, you must specify basic configurations. This topic describes these configurations.
The SDKs for all languages define a Client class that serves as the entry point. You must specify the basic configurations when you construct an instance of this class.
These configurations include the following:
Endpoint: The service endpoint that the client needs to access.
Alibaba Cloud AccessKey: The AccessKey ID and AccessKey secret that the client uses to access Cloud Managed Network.
The following sections describe how to use these two configurations.
Endpoint
Before you use the SDK, identify the region of the Cloud Managed Network service, such as China (Hangzhou). Then, select the corresponding endpoint to initialize the client. This endpoint is the same as the one defined in the API.
Ensure that the endpoint region matches the region that you want to access. Otherwise, the SDK cannot access your specified region.
The endpoint can only be specified when you construct a client instance. To access different regions, construct a separate client instance for each endpoint.
All API endpoints support the HTTPS protocol.
If you use the SDK on an Alibaba Cloud ECS virtual machine, you can use a private network endpoint to avoid public bandwidth overhead.
AccessKey
All requests to Cloud Managed Network must be authenticated using an AccessKey pair. An AccessKey pair consists of an AccessKey ID and an AccessKey secret. When you construct a client, you must specify this pair. Before you use the SDK, obtain or create a suitable key pair on the key management page in the Alibaba Cloud Management Console.
Your account can have multiple AccessKey pairs. However, the AccessKey ID and AccessKey secret that you specify when you construct a client must belong to the same pair. Otherwise, the request fails security authentication on the server.
The specified AccessKey pair must be enabled. Otherwise, the server will deny the request. You can check the status of your AccessKey pairs in the console.
Example
Suppose you want to access Cloud Managed Network in a specific region and you have an enabled AccessKey pair as follows:
AccessKeyId = "ywgiwfns**************"
AccessKeySecret = "4fdO2fTDDnZPU/*************"Instantiate the client as follows:
Java
Config authConfig = new Config();
/**
* An AccessKey for an Alibaba Cloud account has permissions to access all APIs. Use a RAM user for API access or routine O&M.
* Do not hard-code the AccessKey ID and AccessKey secret in your project code. Otherwise, the AccessKey pair may be leaked, which compromises the security of all the resources in your account.
* Before you make an API call, configure identity authentication. For more information, see https://help.aliyun.com/document_detail/378657.html.
* This example uses Alibaba Cloud Credentials to manage the AccessKey for API access authentication.
*/
com.aliyun.credentials.Client credentialClient = new com.aliyun.credentials.Client();
authConfig.endpoint = "region_endpoint"; // Replace this with your actual endpoint and connection type.
authConfig.regionId = "cn-hangzhou"; // Replace this with your actual service region.
authConfig.setCredential(credentialClient);
Client authClient = new Client(authConfig);