Search in sources :

Example 91 with Instance

use of software.amazon.awssdk.services.ec2.model.Instance in project aws-doc-sdk-examples by awsdocs.

the class CreateInstance method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage:\n" + "   <name> <amiId>\n\n" + "Where:\n" + "   name - an instance name value that you can obtain from the AWS Console (for example, ami-xxxxxx5c8b987b1a0). \n\n" + "   amiId - an Amazon Machine Image (AMI) value that you can obtain from the AWS Console (for example, i-xxxxxx2734106d0ab). \n\n";
    if (args.length != 2) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String name = args[0];
    String amiId = args[1];
    Region region = Region.US_WEST_2;
    Ec2Client ec2 = Ec2Client.builder().region(region).build();
    String instanceId = createEC2Instance(ec2, name, amiId);
    System.out.println("The Amazon EC2 Instance ID is " + instanceId);
    ec2.close();
}
Also used : Region(software.amazon.awssdk.regions.Region) Ec2Client(software.amazon.awssdk.services.ec2.Ec2Client)

Example 92 with Instance

use of software.amazon.awssdk.services.ec2.model.Instance in project aws-doc-sdk-examples by awsdocs.

the class DescribeInstanceTags method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage:\n" + "   <resourceId> \n\n" + "Where:\n" + "   resourceId - the instance ID value that you can obtain from the AWS Console (for example, i-xxxxxx0913e05f482). \n\n";
    if (args.length != 1) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String resourceId = args[0];
    Region region = Region.US_EAST_1;
    Ec2Client ec2 = Ec2Client.builder().region(region).build();
    describeEC2Tags(ec2, resourceId);
    ec2.close();
}
Also used : Region(software.amazon.awssdk.regions.Region) Ec2Client(software.amazon.awssdk.services.ec2.Ec2Client)

Example 93 with Instance

use of software.amazon.awssdk.services.ec2.model.Instance in project aws-doc-sdk-examples by awsdocs.

the class MonitorInstance method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage:\n" + "   <instanceId> <monitor>\n\n" + "Where:\n" + "   instanceId - an instance id value that you can obtain from the AWS Console. \n\n" + "   monitor - a monitoring status (true|false)";
    if (args.length != 2) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String instanceId = args[0];
    boolean monitor = Boolean.valueOf(args[1]);
    Region region = Region.US_WEST_2;
    Ec2Client ec2 = Ec2Client.builder().region(region).build();
    if (monitor) {
        monitorInstance(ec2, instanceId);
    } else {
        unmonitorInstance(ec2, instanceId);
    }
    ec2.close();
}
Also used : Region(software.amazon.awssdk.regions.Region) Ec2Client(software.amazon.awssdk.services.ec2.Ec2Client)

Example 94 with Instance

use of software.amazon.awssdk.services.ec2.model.Instance in project aws-doc-sdk-examples by awsdocs.

the class MonitorInstance method monitorInstance.

// snippet-start:[ec2.java2.monitor_instance.main]
public static void monitorInstance(Ec2Client ec2, String instanceId) {
    MonitorInstancesRequest request = MonitorInstancesRequest.builder().instanceIds(instanceId).build();
    ec2.monitorInstances(request);
    System.out.printf("Successfully enabled monitoring for instance %s", instanceId);
}
Also used : MonitorInstancesRequest(software.amazon.awssdk.services.ec2.model.MonitorInstancesRequest)

Example 95 with Instance

use of software.amazon.awssdk.services.ec2.model.Instance in project airavata by apache.

the class AmazonUtil method loadInstances.

/**
 * Load instances
 *
 * @return list of instances
 */
public static List<Instance> loadInstances() {
    List<Instance> resultList = new ArrayList<Instance>();
    DescribeInstancesResult describeInstancesResult = getEC2Client().describeInstances();
    List<Reservation> reservations = describeInstancesResult.getReservations();
    for (Iterator<Reservation> iterator = reservations.iterator(); iterator.hasNext(); ) {
        Reservation reservation = iterator.next();
        for (Instance instance : reservation.getInstances()) {
            resultList.add(instance);
        }
    }
    return resultList;
}
Also used : DescribeInstancesResult(com.amazonaws.services.ec2.model.DescribeInstancesResult) Reservation(com.amazonaws.services.ec2.model.Reservation) Instance(com.amazonaws.services.ec2.model.Instance) ArrayList(java.util.ArrayList)

Aggregations

Instance (com.amazonaws.services.ec2.model.Instance)86 ArrayList (java.util.ArrayList)43 Reservation (com.amazonaws.services.ec2.model.Reservation)39 DescribeInstancesResult (com.amazonaws.services.ec2.model.DescribeInstancesResult)31 List (java.util.List)23 DescribeInstancesRequest (com.amazonaws.services.ec2.model.DescribeInstancesRequest)22 HashMap (java.util.HashMap)22 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)18 Operation (com.vmware.xenon.common.Operation)18 Tag (com.amazonaws.services.ec2.model.Tag)17 Map (java.util.Map)17 Test (org.junit.Test)16 Filter (com.amazonaws.services.ec2.model.Filter)14 HashSet (java.util.HashSet)13 Volume (com.amazonaws.services.ec2.model.Volume)12 Utils (com.vmware.xenon.common.Utils)12 TimeUnit (java.util.concurrent.TimeUnit)12 AmazonEC2AsyncClient (com.amazonaws.services.ec2.AmazonEC2AsyncClient)11 SecurityGroup (com.amazonaws.services.ec2.model.SecurityGroup)11 ComputeService (com.vmware.photon.controller.model.resources.ComputeService)10