本文共 2196 字,大约阅读时间需要 7 分钟。
API简介
如果您熟悉网络服务协议和一种以上编程语言,推荐您调用API管理您的云上资源和开发自己的应用程序。Java SDK示例
示例代码中的下列参数需要您根据实际情况自行填写。:您的AccessKeyId。获取方式请参见创建AccessKey。
:您的AccessKeySecret。 :ECS实例所在的地域ID。取值请参见地域和可用区或DescribeRegions。 :云盘ID。取值请参见DescribeDisks。import com.aliyuncs.DefaultAcsClient;import com.aliyuncs.IAcsClient;import com.aliyuncs.ecs.model.v20140526.CreateSnapshotRequest;import com.aliyuncs.ecs.model.v20140526.CreateSnapshotResponse;import com.aliyuncs.exceptions.ClientException;import com.aliyuncs.exceptions.ServerException;import com.aliyuncs.profile.DefaultProfile;/* pom.xmlcom.aliyun aliyun-java-sdk-core 3.0.9 */ public class CreateSnapshotExample { private String accessKeyId = " com.aliyun aliyun-java-sdk-ecs 4.10.1 "; private String accessSecret = " "; /** * 云盘所在的地域ID */ private String regionId = " "; /** * 要创建快照的云盘ID */ private String diskId = " "; public void createSnapshot() { DefaultProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessSecret); IAcsClient client = new DefaultAcsClient(profile); CreateSnapshotRequest request = new CreateSnapshotRequest(); request.setRegionId(regionId); request.setDiskId(diskId); try { CreateSnapshotResponse response = client.getAcsResponse(request); logInfo(response.getSnapshotId()); } catch (ServerException e) { logInfo(String.format("Fail. Something with your connection with Aliyun go incorrect. ErrorCode: %s", e.getErrCode())); } catch (ClientException e) { logInfo(String.format("Fail. Business error. ErrorCode: %s, RequestId: %s", e.getErrCode(), e.getRequestId())); } } private static void logInfo(String message) { System.out.println(message); } public static void main(String[] args) { new CreateSnapshotExample().createSnapshot(); }}
.
转载地址:http://tsxkk.baihongyu.com/