-
Notifications
You must be signed in to change notification settings - Fork 0
/
EC2Launch.java
35 lines (30 loc) · 1.52 KB
/
EC2Launch.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.io.File;
import java.io.FileInputStream;
import java.util.List;
import com.amazonaws.AmazonServiceException;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.PropertiesCredentials;
import com.amazonaws.services.ec2.AmazonEC2;
import com.amazonaws.services.ec2.AmazonEC2Client;
import com.amazonaws.services.ec2.model.Instance;
import com.amazonaws.services.ec2.model.InstanceType;
import com.amazonaws.services.ec2.model.RunInstancesRequest;
public class EC2Launch {
public static void main(String[] args) throws Exception {
AmazonEC2 ec2;
AWSCredentials credentials = new PropertiesCredentials(new FileInputStream("C:\\Users\\Haymi\\Documents\\BGU\\DSP\\rootkey.properties"));
ec2 = new AmazonEC2Client(credentials);
try {
// Basic 32-bit Amazon Linux AMI 1.0 (AMI Id: ami-08728661)
RunInstancesRequest request = new RunInstancesRequest("ami-08728661", 1, 1);
request.setInstanceType(InstanceType.T1Micro.toString());
List<Instance> instances = ec2.runInstances(request).getReservation().getInstances();
System.out.println("Launch instances: " + instances);
} catch (AmazonServiceException ase) {
System.out.println("Caught Exception: " + ase.getMessage());
System.out.println("Reponse Status Code: " + ase.getStatusCode());
System.out.println("Error Code: " + ase.getErrorCode());
System.out.println("Request ID: " + ase.getRequestId());
}
}
}