All Products
Search
Document Center

Data Online Migration:Initialize a client

Last Updated:Dec 11, 2025

This topic describes how to initialize a client for using Data Online Migration SDK for Java. Before you use Data Online Migration SDK for Go to initiate a request, you must initialize a client with access credentials. Alibaba Cloud services use the access credentials to verify your identity information and access permissions.

Prerequisites

Data Online Migration SDK for Java is installed. For more information, see Install the SDK.

Access credentials

Warning

An Alibaba Cloud account has full permissions on resources within the account. AccessKey pair leaks of an Alibaba Cloud account pose critical threats to the system. Therefore, we recommend that you use the AccessKey pair of a Resource Access Management (RAM) user that is granted permissions based on the principle of least privilege.

You can choose one of the following types of access credentials.

  • Temporary access credentials: For scenarios that require high security, we recommend that you use temporary access credentials. Temporary access credentials are valid only within a specific period of time, which helps prevent credential leaks. Temporary access credentials support fine-grained access control. This helps effectively prevent security risks caused by excessive permissions.

  • Long-term access credentials: To ensure data security, we recommend that you do not use long-term access credentials. For scenarios that require convenience, long-term access credentials eliminate the need for multiple refreshes within a long period of time. We recommend that you change your long-term access credentials every three months to ensure the security of your Alibaba Cloud account. If long-term access credentials are leaked or no longer used, you must delete or disable the long-term access credentials at the earliest opportunity to reduce security risks.

Use temporary access credentials to initialize a client

  1. Use temporary access credentials to specify environment variables.

Mac OS X/Linux/Unix

export ALIBABA_CLOUD_ACCESS_KEY_ID=<ALIBABA_CLOUD_ACCESS_KEY_ID>
export ALIBABA_CLOUD_ACCESS_KEY_SECRET=<ALIBABA_CLOUD_ACCESS_KEY_SECRET>
export ALIBABA_CLOUD_SECURITY_TOKEN=<ALIBABA_CLOUD_SECURITY_TOKEN>

Windows

set ALIBABA_CLOUD_ACCESS_KEY_ID=<ALIBABA_CLOUD_ACCESS_KEY_ID>
set ALIBABA_CLOUD_ACCESS_KEY_SECRET=<ALIBABA_CLOUD_ACCESS_KEY_SECRET>
set ALIBABA_CLOUD_SECURITY_TOKEN=<ALIBABA_CLOUD_SECURITY_TOKEN>
  1. Initialize a client.

package sample;

import com.aliyun.hcs_mgw20240626.Client;

public class StsTest {
	/** We strongly recommend that you 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 your resources. */
	static String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
	static String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
	static String securityToken = System.getenv("ALIBABA_CLOUD_SECURITY_TOKEN");

	public static void main(String[] args) throws Exception {
		com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
		// This example uses the China (Beijing) region.
		config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
		config.setAccessKeyId(accessKeyId);
		config.setAccessKeySecret(accessKeySecret);
		config.setSecurityToken(securityToken);
		// HTTPS and HTTP are supported. If you do not specify the protocol, HTTPS is used by default.
		config.setProtocol("http");
		Client client = new com.aliyun.hcs_mgw20240626.Client(config);
		// Use the initialized client for subsequent operations.
	}
}

Use long-term access credentials to initialize a client

  1. Use long-term access credentials to specify environment variables.

Mac OS X/Linux/Unix

export ALIBABA_CLOUD_ACCESS_KEY_ID=<ALIBABA_CLOUD_ACCESS_KEY_ID>
export ALIBABA_CLOUD_ACCESS_KEY_SECRET=<ALIBABA_CLOUD_ACCESS_KEY_SECRET>

Windows

setx ALIBABA_CLOUD_ACCESS_KEY_ID "ALIBABA_CLOUD_ACCESS_KEY_ID"
setx ALIBABA_CLOUD_ACCESS_KEY_SECRET "ALIBABA_CLOUD_ACCESS_KEY_SECRET"
  1. Initialize a client.

package sample;

import com.aliyun.hcs_mgw20240626.Client;

public class SampleTest {
	/** We strongly recommend that you 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 your resources. */
	static String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
	static String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");

	public static void main(String[] args) throws Exception {
		com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
		// This example uses the China (Beijing) region.
		config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
		config.setAccessKeyId(accessKeyId);
		config.setAccessKeySecret(accessKeySecret);
		// HTTPS and HTTP are supported. If you do not specify the protocol, HTTPS is used by default.
		config.setProtocol("http");
		Client client = new com.aliyun.hcs_mgw20240626.Client(config);
		// Use the initialized client for subsequent operations.
	}
}

What to do next

After you initialize the client, you can perform operations on channels, proxies, data addresses, and tasks. Channels and proxies are used only in leased line or VPN scenarios.