use of software.amazon.awssdk.services.ec2.model.Instance in project SimianArmy by Netflix.
the class InstanceInVPC method checkInstancesInVPC.
private Set<String> checkInstancesInVPC(String region, Collection<String> instances) {
Set<String> failedInstances = Sets.newHashSet();
for (String instanceId : instances) {
for (Instance awsInstance : getAWSInstances(region, instanceId)) {
if (awsInstance.getVpcId() == null) {
LOGGER.info(String.format("Instance %s is not in a virtual private cloud", instanceId));
failedInstances.add(instanceId);
}
}
}
return failedInstances;
}
use of software.amazon.awssdk.services.ec2.model.Instance in project SimianArmy by Netflix.
the class InstanceTooOld method getInstanceLaunchTimes.
/**
* Gets the launch time (in milliseconds) for a list of instance ids of the same region. The default
* implementation is using an AWS client. The method can be overridden in subclasses to get the instance
* launch times differently.
* @param region
* the region of the instances
* @param instanceIds
* the instance ids, all instances should be in the same region.
* @return
* the map from instance id to the launch time in milliseconds
*/
protected Map<String, Long> getInstanceLaunchTimes(String region, String... instanceIds) {
Map<String, Long> result = Maps.newHashMap();
if (instanceIds == null || instanceIds.length == 0) {
return result;
}
AWSClient awsClient = new AWSClient(region, awsCredentialsProvider);
for (Instance instance : awsClient.describeInstances(instanceIds)) {
if (instance.getLaunchTime() != null) {
result.put(instance.getInstanceId(), instance.getLaunchTime().getTime());
} else {
LOGGER.warn(String.format("No launch time found for instance %s", instance.getInstanceId()));
}
}
return result;
}
use of software.amazon.awssdk.services.ec2.model.Instance in project aws-doc-sdk-examples by awsdocs.
the class RebootInstance method rebootEC2Instance.
// snippet-start:[ec2.java2.reboot_instance.main]
public static void rebootEC2Instance(Ec2Client ec2, String instanceId) {
try {
RebootInstancesRequest request = RebootInstancesRequest.builder().instanceIds(instanceId).build();
ec2.rebootInstances(request);
System.out.printf("Successfully rebooted instance %s", instanceId);
} catch (Ec2Exception e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.ec2.model.Instance in project aws-doc-sdk-examples by awsdocs.
the class StartStopInstance method startInstance.
// snippet-start:[ec2.java2.start_stop_instance.start]
public static void startInstance(Ec2Client ec2, String instanceId) {
StartInstancesRequest request = StartInstancesRequest.builder().instanceIds(instanceId).build();
ec2.startInstances(request);
System.out.printf("Successfully started instance %s", instanceId);
}
use of software.amazon.awssdk.services.ec2.model.Instance in project aws-doc-sdk-examples by awsdocs.
the class StartStopInstance method main.
public static void main(String[] args) {
final String USAGE = "\n" + "Usage:\n" + " <instanceId>\n\n" + "Where:\n" + " instanceId - an instance id value that you can obtain from the AWS Console. \n\n";
if (args.length != 1) {
System.out.println(USAGE);
System.exit(1);
}
String instanceId = args[0];
boolean start;
Region region = Region.US_WEST_2;
Ec2Client ec2 = Ec2Client.builder().region(region).build();
if (args[1].equals("start")) {
start = true;
} else {
start = false;
}
if (start) {
startInstance(ec2, instanceId);
} else {
stopInstance(ec2, instanceId);
}
ec2.close();
}
Aggregations