Search in sources :

Example 1 with TerminateInstancesResponse

use of software.amazon.awssdk.services.ec2.model.TerminateInstancesResponse in project aws-doc-sdk-examples by awsdocs.

the class TerminateInstance method terminateEC2.

// snippet-start:[ec2.java2.terminate_instance]
public static void terminateEC2(Ec2Client ec2, String instanceID) {
    try {
        TerminateInstancesRequest ti = TerminateInstancesRequest.builder().instanceIds(instanceID).build();
        TerminateInstancesResponse response = ec2.terminateInstances(ti);
        List<InstanceStateChange> list = response.terminatingInstances();
        for (int i = 0; i < list.size(); i++) {
            InstanceStateChange sc = (list.get(i));
            System.out.println("The ID of the terminated instance is " + sc.instanceId());
        }
    } catch (Ec2Exception e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : Ec2Exception(software.amazon.awssdk.services.ec2.model.Ec2Exception) TerminateInstancesResponse(software.amazon.awssdk.services.ec2.model.TerminateInstancesResponse) TerminateInstancesRequest(software.amazon.awssdk.services.ec2.model.TerminateInstancesRequest) InstanceStateChange(software.amazon.awssdk.services.ec2.model.InstanceStateChange)

Aggregations

Ec2Exception (software.amazon.awssdk.services.ec2.model.Ec2Exception)1 InstanceStateChange (software.amazon.awssdk.services.ec2.model.InstanceStateChange)1 TerminateInstancesRequest (software.amazon.awssdk.services.ec2.model.TerminateInstancesRequest)1 TerminateInstancesResponse (software.amazon.awssdk.services.ec2.model.TerminateInstancesResponse)1