//snippet-sourcedescription:[RebootInstance.java demonstrates how to reboot an EC2 instance in code.]
//snippet-keyword:[SDK for Java 2.0]
//snippet-keyword:[Code Sample]
//snippet-service:[ec2]
//snippet-sourcetype:[full-example]
//snippet-sourcedate:[2020-01-10]
//snippet-sourceauthor:[scmacdon]
/*
 * Copyright 2010-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License").
 * You may not use this file except in compliance with the License.
 * A copy of the License is located at
 *
 *  http://aws.amazon.com/apache2.0
 *
 * or in the "license" file accompanying this file. This file is distributed
 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */
package com.example.ec2;
// snippet-start:[ec2.java2.reboot_instance.complete]
// snippet-start:[ec2.java2.reboot_instance.import]
import software.amazon.awssdk.services.ec2.Ec2Client;
import software.amazon.awssdk.services.ec2.model.RebootInstancesRequest;
import software.amazon.awssdk.services.ec2.model.RebootInstancesResponse;

// snippet-end:[ec2.java2.reboot_instance.import]
/**
 * Reboots and EC2 instance
 */
public class RebootInstance {

    public static void main(String[] args) {
        final String USAGE =
                "To run this example, supply an instance id\n" +
                        "Ex: RebootInstance <instance_id>\n";

        if (args.length != 1) {
            System.out.println(USAGE);
            System.exit(1);
        }

        String instanceId = args[0];
        // snippet-start:[ec2.java2.reboot_instance.main]

        Ec2Client ec2 = Ec2Client.create();

        RebootInstancesRequest request = RebootInstancesRequest.builder()
                .instanceIds(instanceId).build();

        RebootInstancesResponse response = ec2.rebootInstances(request);

        // snippet-end:[ec2.java2.reboot_instance.main]
        System.out.printf(
                "Successfully rebooted instance %s", instanceId);
    }
}

// snippet-end:[ec2.java2.reboot_instance.complete]

@@ -72,16 +72,23 @@
 boot an 
+Amazon 
 EC2 inst
@@ -193,18 +193,25 @@
 ervice:%5B
-ec
+Amazon EC
 2%5D%0D%0A//sn
@@ -270,16 +270,15 @@
 e:%5B2
-020-01-1
+/12/202
 0%5D%0D%0A
@@ -333,18 +333,8 @@
 ght 
-2010-2020 
 Amaz
@@ -931,61 +931,8 @@
 2;%0D%0A
-// snippet-start:%5Bec2.java2.reboot_instance.complete%5D
 %0D%0A//
@@ -982,16 +982,63 @@
 mport%5D%0D%0A
+import software.amazon.awssdk.regions.Region;%0D%0A
 import s
@@ -1080,24 +1080,88 @@
 Ec2Client;%0D%0A
+import software.amazon.awssdk.services.ec2.model.Ec2Exception;%0D%0A
 import softw
@@ -1225,83 +1225,8 @@
 st;%0D
-%0Aimport software.amazon.awssdk.services.ec2.model.RebootInstancesResponse;%0D
 %0A%0D%0A/
@@ -1707,20 +1707,260 @@
 gs%5B0%5D;%0D%0A
+%0D%0A
     
+    //Create an Ec2Client object%0D%0A        Region region = Region.US_WEST_2;%0D%0A        Ec2Client ec2 = Ec2Client.builder()%0D%0A                .region(region)%0D%0A                .build();%0D%0A%0D%0A        rebootEC2Instance(ec2, instanceId);%0D%0A    %7D%0D%0A%0D%0A
     // s
@@ -2010,57 +2010,107 @@
 n%5D%0D%0A
-%0D%0A
     
-    Ec2Client ec2 = Ec2Client.create();%0D%0A%0D%0A
+public static void rebootEC2Instance(Ec2Client ec2, String instanceId) %7B%0D%0A%0D%0A      try %7B%0D%0A%0D%0A    
     
@@ -2245,42 +2245,11 @@
     
-RebootInstancesResponse response =
+   
  ec2
@@ -2280,67 +2280,12 @@
 );%0D%0A
-%0D%0A
     
-    // snippet-end:%5Bec2.java2.reboot_instance.main%5D%0D%0A
     
@@ -2384,15 +2384,147 @@
    %7D
-%0D%0A%7D%0D%0A%0D%0A
+ catch (Ec2Exception e) %7B%0D%0A          System.err.println(e.awsErrorDetails().errorMessage());%0D%0A          System.exit(1);%0D%0A      %7D%0D%0A  %7D%0D%0A    
 // s
@@ -2565,15 +2565,14 @@
 nce.
-complete%5D
+main%5D%0D%0A%7D
 %0D%0A

Update RebootInstance.java