Example usage for com.amazonaws.services.ec2.model StopInstancesRequest getDryRunRequest

List of usage examples for com.amazonaws.services.ec2.model StopInstancesRequest getDryRunRequest

Introduction

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

Prototype

@Override
public Request<StopInstancesRequest> getDryRunRequest() 

Source Link

Document

This method is intended for internal use only.

Usage

From source file:aws.example.ec2.StartStopInstance.java

License:Open Source License

public static void stopInstance(String instance_id) {
    final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();

    DryRunSupportedRequest<StopInstancesRequest> dry_request = () -> {
        StopInstancesRequest request = new StopInstancesRequest().withInstanceIds(instance_id);

        return request.getDryRunRequest();
    };//from w w w .  j  a v  a 2s. c o m

    DryRunResult dry_response = ec2.dryRun(dry_request);

    if (!dry_response.isSuccessful()) {
        System.out.printf("Failed dry run to stop instance %s", instance_id);
        throw dry_response.getDryRunResponse();
    }

    StopInstancesRequest request = new StopInstancesRequest().withInstanceIds(instance_id);

    ec2.stopInstances(request);

    System.out.printf("Successfully stop instance %s", instance_id);
}

From source file:ec2.StartStopInstance.java

License:Open Source License

public static void stopInstance(String instanceId) {

    final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();

    DryRunSupportedRequest<StopInstancesRequest> stopInstanceDryRun = () -> {
        StopInstancesRequest request = new StopInstancesRequest().withInstanceIds(instanceId);

        return request.getDryRunRequest();
    };//from   w w w . j av a  2 s  . c  o  m

    DryRunResult dryRunResponse = ec2.dryRun(stopInstanceDryRun);

    if (!dryRunResponse.isSuccessful()) {
        System.out.printf("Failed dry run to stop instance %s", instanceId);
        throw dryRunResponse.getDryRunResponse();
    }

    StopInstancesRequest request = new StopInstancesRequest().withInstanceIds(instanceId);

    ec2.stopInstances(request);

    System.out.printf("Successfully stop instance %s", instanceId);
}