Ejemplo n.º 1
0
 public void createECAccordingAMI(String ami) {
   amazonClient.runInstances(
       new RunInstancesRequest()
           .withImageId(ami)
           .withMinCount(1)
           .withMaxCount(1)
           .withInstanceType(
               InstanceType.fromValue(configuration.requiredOption("amazon.instance.type"))));
 }
Ejemplo n.º 2
0
  public static void main(String[] args) {
    System.out.println("Hello, World!");
    AmazonEC2Client ec2 = new AmazonEC2Client();
    Region usWest2 = Region.getRegion(Regions.US_WEST_2);
    ec2.setRegion(usWest2);
    RunInstancesRequest req = new RunInstancesRequest();
    req.setImageId("ami-5189a661");
    req.setInstanceType("t2.micro");
    req.setKeyName("aws_pt-user");

    req.setMinCount(1);
    req.setMaxCount(1);

    RunInstancesResult result = ec2.runInstances(req);
    System.out.println(result.toString());
  }
Ejemplo n.º 3
0
  public Instance startInstance(AWSCredentials credentials) {
    AmazonEC2Client amazonEC2Client = new AmazonEC2Client(credentials);

    RunInstancesRequest runInstancesRequest =
        new RunInstancesRequest()
            .withImageId("")
            .withInstanceType("m1.small")
            .withMinCount(1)
            .withMaxCount(1);

    RunInstancesResult runInstancesResult = amazonEC2Client.runInstances(runInstancesRequest);

    Reservation reservation = runInstancesResult.getReservation();
    List<Instance> instances = reservation.getInstances();

    // there will be exactly one instance in this list, otherwise
    // runInstances() would have thrown an exception
    return instances.get(0);
  }