use of software.amazon.awssdk.services.ec2.model.RunInstancesRequest in project airavata by apache.
the class AmazonUtil method launchInstance.
/**
* Launch a new EC2 instance
*
* @param AMI_ID
* @param type
* @param number
* @return list of newly launched instances
*/
public static List<Instance> launchInstance(String AMI_ID, String type, Integer number) {
List<Instance> resultList = new ArrayList<Instance>();
RunInstancesRequest request = new RunInstancesRequest(AMI_ID, number, number);
request.setInstanceType(type);
RunInstancesResult result = getEC2Client().runInstances(request);
resultList.addAll(result.getReservation().getInstances());
return resultList;
}
use of software.amazon.awssdk.services.ec2.model.RunInstancesRequest in project photon-model by vmware.
the class TestAWSSetupUtils method provisionAWSEBSVMWithEC2Client.
public static String provisionAWSEBSVMWithEC2Client(VerificationHost host, AmazonEC2Client client, String ami, String subnetId, String securityGroupId, BlockDeviceMapping blockDeviceMapping) {
RunInstancesRequest runInstancesRequest = new RunInstancesRequest().withSubnetId(subnetId).withImageId(ami).withInstanceType(instanceType).withMinCount(1).withMaxCount(1).withSecurityGroupIds(securityGroupId).withBlockDeviceMappings(blockDeviceMapping);
// handler invoked once the EC2 runInstancesAsync commands completes
RunInstancesResult result = null;
try {
result = client.runInstances(runInstancesRequest);
} catch (Exception e) {
host.log(Level.SEVERE, "Error encountered in provisioning machine on AWS", Utils.toString(e));
}
assertNotNull(result);
assertNotNull(result.getReservation());
assertNotNull(result.getReservation().getInstances());
assertEquals(1, result.getReservation().getInstances().size());
String instanceId = result.getReservation().getInstances().get(0).getInstanceId();
tagResources(client, Arrays.asList(instanceId), TAG_KEY_FOR_TEST_RESOURCES, TAG_VALUE_FOR_TEST_RESOURCES + TAG_INSTANCE);
return instanceId;
}
use of software.amazon.awssdk.services.ec2.model.RunInstancesRequest in project photon-model by vmware.
the class TestAWSSetupUtils method provisionAWSVMWithEC2Client.
public static String provisionAWSVMWithEC2Client(VerificationHost host, AmazonEC2Client client, String ami, String subnetId, String securityGroupId) {
RunInstancesRequest runInstancesRequest = new RunInstancesRequest().withSubnetId(subnetId).withImageId(ami).withInstanceType(instanceType).withMinCount(1).withMaxCount(1).withSecurityGroupIds(securityGroupId);
// handler invoked once the EC2 runInstancesAsync commands completes
RunInstancesResult result = null;
try {
result = client.runInstances(runInstancesRequest);
} catch (Exception e) {
host.log(Level.SEVERE, "Error encountered in provisioning machine on AWS", Utils.toString(e));
}
assertNotNull(result);
assertNotNull(result.getReservation());
assertNotNull(result.getReservation().getInstances());
assertEquals(1, result.getReservation().getInstances().size());
String instanceId = result.getReservation().getInstances().get(0).getInstanceId();
tagResources(client, Arrays.asList(instanceId), TAG_KEY_FOR_TEST_RESOURCES, TAG_VALUE_FOR_TEST_RESOURCES + TAG_INSTANCE);
return instanceId;
}
use of software.amazon.awssdk.services.ec2.model.RunInstancesRequest in project airavata by apache.
the class AmazonUtil method launchInstance.
/**
* Launch a new EC2 instance
*
* @param AMI_ID
* @param type
* @param number
* @param keyname
* @return list of newly launched instances
*/
public static List<Instance> launchInstance(String AMI_ID, String type, Integer number, String keyname) {
List<Instance> resultList = new ArrayList<Instance>();
RunInstancesRequest request = new RunInstancesRequest(AMI_ID, number, number);
request.setInstanceType(type);
request.setKeyName(keyname);
RunInstancesResult result = getEC2Client().runInstances(request);
resultList.addAll(result.getReservation().getInstances());
return resultList;
}
use of software.amazon.awssdk.services.ec2.model.RunInstancesRequest in project aws-doc-sdk-examples by awsdocs.
the class CreateInstance method main.
public static void main(String[] args) {
final String USAGE = "To run this example, supply an instance name and AMI image id\n" + "Ex: CreateInstance <instance-name> <ami-image-id>\n";
if (args.length != 2) {
System.out.println(USAGE);
System.exit(1);
}
String name = args[0];
String ami_id = args[1];
final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();
RunInstancesRequest run_request = new RunInstancesRequest().withImageId(ami_id).withInstanceType(InstanceType.T1Micro).withMaxCount(1).withMinCount(1);
RunInstancesResult run_response = ec2.runInstances(run_request);
String reservation_id = run_response.getReservation().getInstances().get(0).getInstanceId();
Tag tag = new Tag().withKey("Name").withValue(name);
CreateTagsRequest tag_request = new CreateTagsRequest().withResources(reservation_id).withTags(tag);
CreateTagsResult tag_response = ec2.createTags(tag_request);
System.out.printf("Successfully started EC2 instance %s based on AMI %s", reservation_id, ami_id);
}
Aggregations