//snippet-sourcedescription:[DescribeInstances.java demonstrates how to get information about all the EC2 instances associated with an AWS account.]
//snippet-keyword:[SDK for Java 2.0]
//snippet-keyword:[Code Sample]
//snippet-service:[ec2]
//snippet-sourcetype:[full-example]
//snippet-sourcedate:[11/02/2020]
//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.describe_instances.complete]

// snippet-start:[ec2.java2.describe_instances.import]
import software.amazon.awssdk.services.ec2.Ec2Client;
import software.amazon.awssdk.services.ec2.model.DescribeInstancesRequest;
import software.amazon.awssdk.services.ec2.model.DescribeInstancesResponse;
import software.amazon.awssdk.services.ec2.model.Instance;
import software.amazon.awssdk.services.ec2.model.Reservation;
import software.amazon.awssdk.services.ec2.model.Ec2Exception;
// snippet-end:[ec2.java2.describe_instances.import]

/**
 * Describes all EC2 instances associated with an AWS account
 */
public class DescribeInstances {

    public static void main(String[] args) {
        Ec2Client ec2 = Ec2Client.create();
        boolean done = false;

        // snippet-start:[ec2.java2.describe_instances.main]
        String nextToken = null;

        try {

            do {
                DescribeInstancesRequest request = DescribeInstancesRequest.builder().maxResults(6).nextToken(nextToken).build();
                DescribeInstancesResponse response = ec2.describeInstances(request);

                for (Reservation reservation : response.reservations()) {
                    for (Instance instance : reservation.instances()) {
                    System.out.printf(
                            "Found reservation with id %s, " +
                                    "AMI %s, " +
                                    "type %s, " +
                                    "state %s " +
                                    "and monitoring state %s",
                            instance.instanceId(),
                            instance.imageId(),
                            instance.instanceType(),
                            instance.state().name(),
                            instance.monitoring().state());
                    System.out.println("");
                }
            }
                nextToken = response.nextToken();
            } while (nextToken != null);

        } catch (Ec2Exception e) {
            e.getStackTrace();
        }
        // snippet-end:[ec2.java2.describe_instances.main]        
    }
}
// snippet-end:[ec2.java2.describe_instances.complete]

@@ -233,18 +233,25 @@
 ervice:%5B
-ec
+Amazon EC
 2%5D%0D%0A//sn
@@ -309,13 +309,12 @@
 te:%5B
+2/
 11
-/02
 /202
@@ -352,16 +352,18 @@
 acdon%5D%0D%0A
+%0D%0A
 /*%0D%0A * C
@@ -375,17 +375,8 @@
 ght 
-2010-2020
  Ama
@@ -973,66 +973,8 @@
 c2;%0D
-%0A// snippet-start:%5Bec2.java2.describe_instances.complete%5D%0D
 %0A%0D%0A/
@@ -1028,16 +1028,63 @@
 mport%5D%0D%0A
+import software.amazon.awssdk.regions.Region;%0D%0A
 import s
@@ -1681,24 +1681,28 @@
 rgs) %7B%0D%0A
+%0D%0A%0D%0A
         
 Ec2Clien
@@ -1697,43 +1697,124 @@
     
-Ec2Client ec2 = Ec2Client.create
+//Create an Ec2Client object%0D%0A        Region region = Region.US_WEST_2;%0D%0A        Ec2Client ec2 = Ec2Client.builder
 ()
-;
 %0D%0A  
@@ -1823,37 +1823,108 @@
     
+    
-boolean done = false;%0D%0A
+    .region(region)%0D%0A                .build();%0D%0A%0D%0A        describeEC2Instances( ec2);
 %0D%0A    
+%7D%0D%0A%0D%0A
     
@@ -1977,16 +1977,111 @@
 .main%5D%0D%0A
+    public static void describeEC2Instances( Ec2Client ec2)%7B%0D%0A%0D%0A        boolean done = false;%0D%0A
         
@@ -3411,24 +3411,16 @@
 es.main%5D
-        
 %0D%0A    %7D%0D
@@ -3427,60 +3427,4 @@
 %0A%7D%0D%0A
-// snippet-end:%5Bec2.java2.describe_instances.complete%5D%0D%0A

Update DescribeInstances.java