I managed to start, stop and check the status of a previously created EC2 instance from the JAVA API. However, it is difficult for me to get the public dns address of this instance. Since I am starting the instance using StartInstancesRequest and getting a response using StartInstancesResponse, I could not get the real instance of the object. My starter code is below, it works:
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; }
In addition, any help connecting to this instance through JSch would be appreciated.
Thanks a lot!
jatha source share