//snippet-sourcedescription:[DescribeReservedInstances.java demonstrates how to get information about EC2 Reserved Instances.]
//snippet-keyword:[SDK for Java 2.0]
//snippet-keyword:[Code Sample]
//snippet-service:[ec2]
//snippet-sourcetype:[full-example]
//snippet-sourcedate:[]
//snippet-sourceauthor:[jschwarzwalder-aws]
/*
 * Copyright 2010-2019 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_reserved_instances.complete]
// snippet-start:[ec2.java2.describe_reserved_instances.import]

import software.amazon.awssdk.services.ec2.Ec2Client;
import software.amazon.awssdk.services.ec2.model.DescribeReservedInstancesRequest;
import software.amazon.awssdk.services.ec2.model.DescribeReservedInstancesResponse;
import software.amazon.awssdk.services.ec2.model.ReservedInstances;
// snippet-end:[ec2.java2.describe_reserved_instances.import]


/**
 * Describes reserved instances
 */
public class DescribeReservedInstances {


    public static void main(String[] args) {
        final String USAGE =
            "To run this example, supply a group id\n" +
                "Ex: DescribeReservedInstances <vpc-id>\n";

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

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

        Ec2Client ec2 = Ec2Client.create();

         DescribeReservedInstancesRequest request = DescribeReservedInstancesRequest.builder().reservedInstancesIds(instanceID).build();

         DescribeReservedInstancesResponse response =
            ec2.describeReservedInstances(request);

        for (ReservedInstances instance : response.reservedInstances()) {
            System.out.printf(
                "Found a reserved instance with id %s, " +
                    "in AZ %s, " +
                    "type %s, " +
                    "state %s " +
                    "and monitoring state %s",
                instance.reservedInstancesId(),
                instance.availabilityZone(),
                instance.instanceType(),
                instance.state().name());

        }

        // snippet-end:[ec2.java2.describe_reserved_instances.main]
    }
}

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

@@ -271,16 +271,26 @@
 cedate:%5B
+11/02/2020
 %5D%0A//snip
@@ -311,26 +311,16 @@
 or:%5B
-j
 sc
-hwarzwalder-aws
+macdon
 %5D%0A/*
@@ -1348,16 +1348,79 @@
 tances;%0A
+import software.amazon.awssdk.services.ec2.model.Ec2Exception;%0A
 // snipp
@@ -1474,17 +1474,16 @@
 mport%5D%0A%0A
-%0A
 /**%0A * D
@@ -1556,17 +1556,16 @@
 nces %7B%0A%0A
-%0A
     publ
@@ -1642,16 +1642,20 @@
         
+    
 %22To run 
@@ -1687,24 +1687,32 @@
 oup id%5Cn%22 +%0A
+        
             
@@ -2018,25 +2018,41 @@
 t.create();%0A
-%0A
+        try %7B%0A   
          Des
@@ -2178,32 +2178,35 @@
 ld();%0A%0A         
+   
 DescribeReserved
@@ -2246,16 +2246,20 @@
         
+    
 ec2.desc
@@ -2299,16 +2299,20 @@
         
+  
+  
 for (Res
@@ -2373,32 +2373,36 @@
 ) %7B%0A            
+    
 System.out.print
@@ -2420,16 +2420,20 @@
         
+ 
+   
 %22Found a
@@ -2487,16 +2487,24 @@
         
+   
+     
 %22in AZ %25
@@ -2530,16 +2530,24 @@
         
+       
+ 
 %22type %25s
@@ -2544,32 +2544,40 @@
   %22type %25s, %22 +%0A
+        
                 
@@ -2614,16 +2614,24 @@
         
+    
+    
 %22and mon
@@ -2649,16 +2649,20 @@
 te %25s%22,%0A
+    
         
@@ -2697,24 +2697,28 @@
 tancesId(),%0A
+    
             
@@ -2758,32 +2758,36 @@
                 
+    
 instance.instanc
@@ -2803,32 +2803,36 @@
                 
+   
+ 
 instance.state()
@@ -2841,17 +2841,16 @@
 ame());%0A
-%0A
         
@@ -2864,77 +2864,78 @@
     
-// snippet-end:%5Bec2.java2.describe_reserved_instances.main%5D
+%7D catch (Ec2Exception e) %7B%0A            e.getStackTrace();
 %0A    %7D%0A
-%7D%0A%0A
+      
 // s
@@ -2972,30 +2972,32 @@
 _reserved_instances.
-complete%5D
+main%5D%0A  %7D%0A%7D
 %0A

Update DescribeReservedInstances.java