use of com.amazonaws.services.ec2.AmazonEC2 in project deeplearning4j by deeplearning4j.
the class Ec2BoxCreator method create.
/**
* Create the instances
*/
public void create() {
RunInstancesRequest runInstancesRequest = new RunInstancesRequest().withImageId(amiId).withInstanceType(size).withKeyName(keyPair).withMinCount(1).withSecurityGroupIds(securityGroupId).withMaxCount(numBoxes);
AmazonEC2 ec2 = getEc2();
ec2.setRegion(com.amazonaws.regions.Region.getRegion(regions));
List<Instance> boxes = ec2.runInstances(runInstancesRequest).getReservation().getInstances();
if (boxesCreated == null) {
boxesCreated = new ArrayList<>();
for (Instance i : boxes) boxesCreated.add(i.getInstanceId());
log.info("Boxes created " + boxesCreated);
} else {
blowupBoxes();
boxesCreated.clear();
for (Instance i : boxes) boxesCreated.add(i.getInstanceId());
}
}
use of com.amazonaws.services.ec2.AmazonEC2 in project elasticsearch by elastic.
the class AwsEc2ServiceImpl method client.
@Override
public synchronized AmazonEC2 client() {
if (client != null) {
return client;
}
this.client = new AmazonEC2Client(buildCredentials(logger, settings), buildConfiguration(logger, settings));
String endpoint = findEndpoint(logger, settings);
if (endpoint != null) {
client.setEndpoint(endpoint);
}
return this.client;
}
use of com.amazonaws.services.ec2.AmazonEC2 in project GNS by MobilityFirst.
the class AWSEC2 method describeInstances.
/**
* Describe Current Instances
*
* @param ec2
*/
public static void describeInstances(AmazonEC2 ec2) {
StringBuilder output = new StringBuilder();
String prefix = currentTab + "Current Instances: ";
DescribeInstancesResult describeInstancesResult = ec2.describeInstances();
List<Reservation> reservations = describeInstancesResult.getReservations();
Set<Instance> instances = new HashSet<Instance>();
// add all instances to a Set.
for (Reservation reservation : reservations) {
instances.addAll(reservation.getInstances());
}
prefix = prefix.concat(" [" + instances.size() + " total] ");
for (Instance ins : instances) {
// instance state
output.append(prefix);
prefix = ", ";
output.append(ins.getPublicDnsName());
output.append(" (");
output.append(ins.getInstanceId());
output.append(") ");
output.append(ins.getState().getName());
}
System.out.println(output);
}
use of com.amazonaws.services.ec2.AmazonEC2 in project GNS by MobilityFirst.
the class AWSEC2 method createAndAttachVolume.
/**
* Creates a volume and attaches and mounts it on the instance at the specified mount point.
*
* @param ec2
* @param instanceId
* @param mountPoint
* @return the id of the volume
*/
public static String createAndAttachVolume(AmazonEC2 ec2, String instanceId, String mountPoint) {
// ATTACH A VOLUME
Instance instance = findInstance(ec2, instanceId);
String zone = instance.getPlacement().getAvailabilityZone();
CreateVolumeRequest newVolumeRequest = new CreateVolumeRequest();
//1.0GB
newVolumeRequest.setSize(1);
// set its available zone, it may change.
newVolumeRequest.setAvailabilityZone(zone);
CreateVolumeResult volumeResult = ec2.createVolume(newVolumeRequest);
Volume v1 = volumeResult.getVolume();
String volumeID = v1.getVolumeId();
//begin to attach the volume to instance
AttachVolumeRequest avr = new AttachVolumeRequest();
avr.withInstanceId(instanceId);
avr.withVolumeId(volumeID);
//mount it
avr.withDevice(mountPoint);
ec2.attachVolume(avr);
System.out.println("EBS volume has been attached and the volume ID is: " + volumeID);
return (volumeID);
}
use of com.amazonaws.services.ec2.AmazonEC2 in project GNS by MobilityFirst.
the class AWSEC2 method main.
/**
*
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
AWSCredentials credentials = new PropertiesCredentials(AWSEC2.class.getResourceAsStream(System.getProperty("user.home") + FILESEPARATOR + ".aws" + FILESEPARATOR + "credentials"));
//Create Amazon Client object
AmazonEC2 ec2 = new AmazonEC2Client(credentials);
RegionRecord region = RegionRecord.US_EAST_1;
String keyName = "aws";
String installScript = "#!/bin/bash\n" + "cd /home/ec2-user\n" + "yum --quiet --assumeyes update\n";
HashMap<String, String> tags = new HashMap<>();
tags.put("runset", new Date().toString());
createAndInitInstance(ec2, region, AMIRecord.getAMI(AMIRecordType.Amazon_Linux_AMI_2013_03_1, region), "Test Instance", keyName, DEFAULT_SECURITY_GROUP_NAME, installScript, tags, "23.21.120.250");
}
Aggregations