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();
}
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();
}
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();
}
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);
}
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;
}
Aggregations