use of com.amazonaws.services.ec2.AmazonEC2 in project eureka by Netflix.
the class ElasticNetworkInterfaceBinder method getEC2Service.
private AmazonEC2 getEC2Service() {
String aWSAccessId = serverConfig.getAWSAccessId();
String aWSSecretKey = serverConfig.getAWSSecretKey();
AmazonEC2 ec2Service;
if (null != aWSAccessId && !"".equals(aWSAccessId) && null != aWSSecretKey && !"".equals(aWSSecretKey)) {
ec2Service = new AmazonEC2Client(new BasicAWSCredentials(aWSAccessId, aWSSecretKey));
} else {
ec2Service = new AmazonEC2Client(new InstanceProfileCredentialsProvider());
}
String region = clientConfig.getRegion();
region = region.trim().toLowerCase();
ec2Service.setEndpoint("ec2." + region + ".amazonaws.com");
return ec2Service;
}
use of com.amazonaws.services.ec2.AmazonEC2 in project GNS by MobilityFirst.
the class AWSEC2 method associateAddress.
/**
*
* @param ec2
* @param ip
* @param instance
*/
public static void associateAddress(AmazonEC2 ec2, String ip, Instance instance) {
Address address;
if ((address = findElasticIP(ec2, ip)) != null) {
if (address.getDomain().equals("vpc")) {
System.out.println("VPC Elastic IP: " + ip);
ec2.associateAddress(new AssociateAddressRequest().withInstanceId(instance.getInstanceId()).withAllocationId(address.getAllocationId()));
} else {
System.out.println("EC2 Classic Elastic IP: " + ip);
ec2.associateAddress(new AssociateAddressRequest(instance.getInstanceId(), ip));
}
}
}
use of com.amazonaws.services.ec2.AmazonEC2 in project GNS by MobilityFirst.
the class AWSEC2 method getInstances.
/**
* Returns all the instances in this region.
*
* @param ec2
* @return a set of instance instances
*/
public static Set<Instance> getInstances(AmazonEC2 ec2) {
Set<Instance> instances = new HashSet<>();
DescribeInstancesResult describeInstancesResult = ec2.describeInstances();
List<Reservation> reservations = describeInstancesResult.getReservations();
// add all instances to a Set.
for (Reservation reservation : reservations) {
instances.addAll(reservation.getInstances());
}
return instances;
}
use of com.amazonaws.services.ec2.AmazonEC2 in project GNS by MobilityFirst.
the class AWSEC2 method terminateInstance.
/**
* Terminate an instance
*
* @param ec2
* @param createdInstanceId
*/
public static void terminateInstance(AmazonEC2 ec2, String createdInstanceId) {
System.out.println("Terminating Instance:" + createdInstanceId);
List<String> instanceIds = new LinkedList<>();
instanceIds.add(createdInstanceId);
TerminateInstancesRequest tir = new TerminateInstancesRequest(instanceIds);
ec2.terminateInstances(tir);
}
use of com.amazonaws.services.ec2.AmazonEC2 in project GNS by MobilityFirst.
the class AWSEC2 method getAvailabilityZones.
/**
* Returns a list of strings of all the availability zones in the current region.
*
* @param ec2
* @return a list of zone strings
*/
public static List<String> getAvailabilityZones(AmazonEC2 ec2) {
ArrayList<String> result = new ArrayList<>();
DescribeAvailabilityZonesResult availabilityZonesResult = ec2.describeAvailabilityZones();
for (AvailabilityZone zone : availabilityZonesResult.getAvailabilityZones()) {
result.add(zone.getZoneName());
}
return result;
}
Aggregations