Search in sources :

Example 1 with DescribeReservedInstancesResponse

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

the class DescribeReservedInstances method describeReservedEC2Instances.

// snippet-start:[ec2.java2.describe_reserved_instances.main]
public static void describeReservedEC2Instances(Ec2Client ec2, String instanceID) {
    try {
        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());
        }
    } catch (Ec2Exception e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : Ec2Exception(software.amazon.awssdk.services.ec2.model.Ec2Exception) DescribeReservedInstancesRequest(software.amazon.awssdk.services.ec2.model.DescribeReservedInstancesRequest) ReservedInstances(software.amazon.awssdk.services.ec2.model.ReservedInstances) DescribeReservedInstancesResponse(software.amazon.awssdk.services.ec2.model.DescribeReservedInstancesResponse)

Aggregations

DescribeReservedInstancesRequest (software.amazon.awssdk.services.ec2.model.DescribeReservedInstancesRequest)1 DescribeReservedInstancesResponse (software.amazon.awssdk.services.ec2.model.DescribeReservedInstancesResponse)1 Ec2Exception (software.amazon.awssdk.services.ec2.model.Ec2Exception)1 ReservedInstances (software.amazon.awssdk.services.ec2.model.ReservedInstances)1