我設法從JAVA API啓動,停止並檢查以前創建的EC2實例的狀態。但是,我很難獲取此實例的公共dns地址。由於我使用StartInstancesRequest啓動實例並使用StartInstancesResponse獲取響應,因此我無法檢索實際的Instance對象。我的起始代碼如下,它的工作原理:從JAVA API獲取Amazon EC2實例的公共DNS
BasicAWSCredentials oAWSCredentials = new BasicAWSCredentials(sAccessKey, sSecretKey);
AmazonEC2 ec2 = new AmazonEC2Client(oAWSCredentials);
ec2.setEndpoint("https://eu-west-1.ec2.amazonaws.com");
List<String> instanceIDs = new ArrayList<String>();
instanceIDs.add("i-XXXXXXX");
StartInstancesRequest startInstancesRequest = new StartInstancesRequest(instanceIDs);
try {
StartInstancesResult response = ec2.startInstances(startInstancesRequest);
System.out.println("Sent! "+response.toString());
}catch (AmazonServiceException ex){
System.out.println(ex.toString());
return false;
}catch(AmazonClientException ex){
System.out.println(ex.toString());
return false;
}
除了任何通過連接到這個實例通過JSch的幫助將不勝感激。
非常感謝!
完美無瑕地工作,非常感謝! – jatha 2012-02-12 14:45:03