Example usage for com.amazonaws.services.ec2.model LaunchSpecification LaunchSpecification

List of usage examples for com.amazonaws.services.ec2.model LaunchSpecification LaunchSpecification

Introduction

In this page you can find the example usage for com.amazonaws.services.ec2.model LaunchSpecification LaunchSpecification.

Prototype

LaunchSpecification

Source Link

Usage

From source file:org.deeplearning4j.aws.ec2.Ec2BoxCreator.java

License:Apache License

public void createSpot() {
    // Initializes a Spot Instance Request
    RequestSpotInstancesRequest requestRequest = new RequestSpotInstancesRequest();

    // Request 1 x t1.micro instance with a bid price of $0.03.
    requestRequest.setSpotPrice("0.03");
    requestRequest.setInstanceCount(Integer.valueOf(1));

    // Setup the specifications of the launch. This includes the
    // instance type (e.g. t1.micro) and the latest Amazon Linux
    // AMI id available. Note, you should always use the latest
    // Amazon Linux AMI id or another of your choosing.
    LaunchSpecification launchSpecification = new LaunchSpecification();
    launchSpecification.setImageId("ami-8c1fece5");
    launchSpecification.setInstanceType("t1.micro");

    // Add the security group to the request.
    List<String> securityGroups = new ArrayList<String>();
    securityGroups.add("GettingStartedGroup");
    launchSpecification.setSecurityGroups(securityGroups);

    // Add the launch specifications to the request.
    requestRequest.setLaunchSpecification(launchSpecification);

    // Call the RequestSpotInstance API.
    RequestSpotInstancesResult requestResult = getEc2().requestSpotInstances(requestRequest);

    List<SpotInstanceRequest> requestResponses = requestResult.getSpotInstanceRequests();

    // Setup an arraylist to collect all of the request ids we want to
    // watch hit the running state.
    List<String> spotInstanceRequestIds = new ArrayList<>();

    // Add all of the request ids to the hashset, so we can determine when they hit the
    // active state.
    for (SpotInstanceRequest requestResponse : requestResponses) {
        System.out.println("Created Spot Request: " + requestResponse.getSpotInstanceRequestId());
        spotInstanceRequestIds.add(requestResponse.getSpotInstanceRequestId());
    }//from w ww  .  j  ava 2 s .  c o  m

}

From source file:org.excalibur.service.aws.ec2.EC2.java

License:Open Source License

public List<SpotInstanceOfferResult> createSpotInstanceOffer(SpotInstanceOffer request) {
    RequestSpotInstancesRequest spotRequest = new RequestSpotInstancesRequest(
            request.getOfferValue().toPlainString()).withValidFrom(request.getValidFrom())
                    .withValidUntil(request.getValidUntil())
                    .withType(SpotInstanceType.fromValue(request.getType().getName()))
                    .withInstanceCount(request.getNumberOfInstances()).withLaunchSpecification(
                            new LaunchSpecification().withInstanceType(request.getInstanceType().getName())
                                    .withImageId(request.getImageId()).withKeyName(request.getKeyName()));

    RequestSpotInstancesResult requestedSpotInstances = ec2_.requestSpotInstances(spotRequest);
    request.setStatus(new InstanceTemplateStatus().setStatus(Status.SUCCESS));

    return toSpotInstanceResults(request, requestedSpotInstances.getSpotInstanceRequests());
}

From source file:scheduler.SpotRequests.java

License:Open Source License

/**
 * The submit method will create 1 x one-time t1.micro request with a maximum bid
 * price of $0.03 using the Amazon Linux AMI.
 *
 * Note the AMI id may change after the release of this code sample, and it is important
 * to use the latest. You can find the latest version by logging into the AWS Management
 * console, and attempting to perform a launch. You will be presented with AMI options,
 * one of which will be Amazon Linux. Simply use that AMI id.
 *//*from w w  w.j  a  v  a 2 s  . co  m*/
public void submitRequests() {
    //==========================================================================//
    //================= Submit a Spot Instance Request =====================//
    //==========================================================================//

    // Initializes a Spot Instance Request
    RequestSpotInstancesRequest requestRequest = new RequestSpotInstancesRequest();

    // Request 1 x t1.micro instance with a bid price of $0.03.
    requestRequest.setSpotPrice("0.03");
    requestRequest.setInstanceCount(Integer.valueOf(1));

    // Setup the specifications of the launch. This includes the instance type (e.g. t1.micro)
    // and the latest Amazon Linux AMI id available. Note, you should always use the latest
    // Amazon Linux AMI id or another of your choosing.
    // ami-3d50120d
    // ami-c9d497f9 (Guan)
    LaunchSpecification launchSpecification = new LaunchSpecification();
    //       launchSpecification.setImageId("ami-c9d497f9");
    launchSpecification.setImageId("ami-c9d497f9");
    launchSpecification.setInstanceType("t1.micro");

    // Add the security group to the request.
    //ArrayList<String> securityGroups = new ArrayList<String>();
    //securityGroups.add("GettingStartedGroup");
    //launchSpecification.setSecurityGroups(securityGroups);

    // Add the launch specifications to the request.
    requestRequest.setLaunchSpecification(launchSpecification);

    // Call the RequestSpotInstance API.
    RequestSpotInstancesResult requestResult = ec2.requestSpotInstances(requestRequest);
    List<SpotInstanceRequest> requestResponses = requestResult.getSpotInstanceRequests();

    // Setup an arraylist to collect all of the request ids we want to watch hit the running
    // state.
    spotInstanceRequestIds = new ArrayList<String>();

    // Add all of the request ids to the hashset, so we can determine when they hit the
    // active state.
    for (SpotInstanceRequest requestResponse : requestResponses) {
        System.out.println("Created Spot Request: " + requestResponse.getSpotInstanceRequestId());
        spotInstanceRequestIds.add(requestResponse.getSpotInstanceRequestId());
    }

}