Get an AccessKey pair
When you use OpenAPI Explorer to manage HTTPDNS, you need an AccessKey pair to call API operations. An AccessKey pair consists of an AccessKey ID and an AccessKey secret.
To ensure the security of cloud services, you must create a RAM user, obtain an AccessKey pair of the RAM user, and then manage HTTPDNS as the RAM user by using OpenAPI Explorer. Perform the following steps:
Create a RAM user. For more information, see Create a RAM user.
Grant permissions to a RAM user to manage HTTPDNS.
Obtain the AccessKey pair of the RAM user. For more information, see Create an AccessKey.
ImportantAn AccessKey pair consists of an AccessKey ID and an AccessKey secret.
Add dependencies
You can add Maven dependencies:
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-httpdns</artifactId>
<version>2.1.2</version>
</dependency>You can also download JAR packages:
Sample code
Before you call the operation, you must configure environment variables and obtain access credentials from the environment variables. Configuration method:
export CC_AK_ENV=<access_key_id> export CC_SK_ENV=<access_key_secret>Replace <access_key_id> with the AccessKey ID of your RAM user and <access_key_secret> with the AccessKey Secret.
import com.aliyuncs.http.HttpResponse;
import com.aliyuncs.httpdns.model.v20160201.*;
import com.aliyuncs.profile.*;
import com.aliyuncs.*;
// Configure SDK Profile
// An Alibaba Cloud account AccessKey pair has permissions to call all API operations. We recommend that you use a RAM user to call API operations or perform routine O&M.
// We recommend that you do not save your AccessKey ID and AccessKey secret in your project code. Otherwise, the AccessKey pair may be leaked and all resources within your account are exposed to risks.
// In this example, the system reads the AccessKey pair from environment variables to implement authentication for API access.
public class DemoListDomains {
public static void main(String[] args) {
String accessKeyId = System.getenv("CC_AK_ENV"); /* Access Key ID */
String accessKeySecret = System.getenv("CC_SK_ENV"); /* Access Key Secret */
IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessKeySecret);
IAcsClient client = new DefaultAcsClient(profile);
ListDomainsRequest request = new ListDomainsRequest();
try {
ListDomainsResponse httpResponse = client.getAcsResponse(request);
System.out.println(httpResponse.getRequestId());
}catch (Exception e) {
e.printStackTrace();
}
}
}