Search in sources :

Example 1 with DryRunResult

use of com.amazonaws.services.ec2.model.DryRunResult in project aws-doc-sdk-examples by awsdocs.

the class MonitorInstance method unmonitorInstance.

public static void unmonitorInstance(String instance_id) {
    final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();
    DryRunSupportedRequest<UnmonitorInstancesRequest> dry_request = () -> {
        UnmonitorInstancesRequest request = new UnmonitorInstancesRequest().withInstanceIds(instance_id);
        return request.getDryRunRequest();
    };
    DryRunResult dry_response = ec2.dryRun(dry_request);
    if (!dry_response.isSuccessful()) {
        System.out.printf("Failed dry run to disable monitoring on instance %s", instance_id);
        throw dry_response.getDryRunResponse();
    }
    UnmonitorInstancesRequest request = new UnmonitorInstancesRequest().withInstanceIds(instance_id);
    ec2.unmonitorInstances(request);
    System.out.printf("Successfully disabled monitoring for instance %s", instance_id);
}
Also used : AmazonEC2(com.amazonaws.services.ec2.AmazonEC2) DryRunResult(com.amazonaws.services.ec2.model.DryRunResult) UnmonitorInstancesRequest(com.amazonaws.services.ec2.model.UnmonitorInstancesRequest)

Example 2 with DryRunResult

use of com.amazonaws.services.ec2.model.DryRunResult in project aws-doc-sdk-examples by awsdocs.

the class StartStopInstance method startInstance.

public static void startInstance(String instance_id) {
    final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();
    DryRunSupportedRequest<StartInstancesRequest> dry_request = () -> {
        StartInstancesRequest request = new StartInstancesRequest().withInstanceIds(instance_id);
        return request.getDryRunRequest();
    };
    DryRunResult dry_response = ec2.dryRun(dry_request);
    if (!dry_response.isSuccessful()) {
        System.out.printf("Failed dry run to start instance %s", instance_id);
        throw dry_response.getDryRunResponse();
    }
    StartInstancesRequest request = new StartInstancesRequest().withInstanceIds(instance_id);
    ec2.startInstances(request);
    System.out.printf("Successfully started instance %s", instance_id);
}
Also used : StartInstancesRequest(com.amazonaws.services.ec2.model.StartInstancesRequest) AmazonEC2(com.amazonaws.services.ec2.AmazonEC2) DryRunResult(com.amazonaws.services.ec2.model.DryRunResult)

Example 3 with DryRunResult

use of com.amazonaws.services.ec2.model.DryRunResult in project aws-doc-sdk-examples by awsdocs.

the class MonitorInstance method monitorInstance.

public static void monitorInstance(String instance_id) {
    final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();
    DryRunSupportedRequest<MonitorInstancesRequest> dry_request = () -> {
        MonitorInstancesRequest request = new MonitorInstancesRequest().withInstanceIds(instance_id);
        return request.getDryRunRequest();
    };
    DryRunResult dry_response = ec2.dryRun(dry_request);
    if (!dry_response.isSuccessful()) {
        System.out.printf("Failed dry run to enable monitoring on instance %s", instance_id);
        throw dry_response.getDryRunResponse();
    }
    MonitorInstancesRequest request = new MonitorInstancesRequest().withInstanceIds(instance_id);
    ec2.monitorInstances(request);
    System.out.printf("Successfully enabled monitoring for instance %s", instance_id);
}
Also used : AmazonEC2(com.amazonaws.services.ec2.AmazonEC2) MonitorInstancesRequest(com.amazonaws.services.ec2.model.MonitorInstancesRequest) DryRunResult(com.amazonaws.services.ec2.model.DryRunResult)

Example 4 with DryRunResult

use of com.amazonaws.services.ec2.model.DryRunResult in project aws-doc-sdk-examples by awsdocs.

the class StartStopInstance method stopInstance.

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();
    };
    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);
}
Also used : StopInstancesRequest(com.amazonaws.services.ec2.model.StopInstancesRequest) AmazonEC2(com.amazonaws.services.ec2.AmazonEC2) DryRunResult(com.amazonaws.services.ec2.model.DryRunResult)

Aggregations

AmazonEC2 (com.amazonaws.services.ec2.AmazonEC2)4 DryRunResult (com.amazonaws.services.ec2.model.DryRunResult)4 MonitorInstancesRequest (com.amazonaws.services.ec2.model.MonitorInstancesRequest)1 StartInstancesRequest (com.amazonaws.services.ec2.model.StartInstancesRequest)1 StopInstancesRequest (com.amazonaws.services.ec2.model.StopInstancesRequest)1 UnmonitorInstancesRequest (com.amazonaws.services.ec2.model.UnmonitorInstancesRequest)1