Search in sources :

Example 1 with DescribeRegionsResponse

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

the class DescribeRegionsAndZones method describeEC2RegionsAndZones.

// snippet-start:[ec2.java2.describe_region_and_zones.main]
public static void describeEC2RegionsAndZones(Ec2Client ec2) {
    // snippet-start:[ec2.java2.describe_region_and_zones.region]
    try {
        DescribeRegionsResponse regionsResponse = ec2.describeRegions();
        for (Region region : regionsResponse.regions()) {
            System.out.printf("Found Region %s " + "with endpoint %s", region.regionName(), region.endpoint());
            System.out.println();
        // snippet-end:[ec2.java2.describe_region_and_zones.region]
        }
        // snippet-start:[ec2.java2.describe_region_and_zones.avail_zone]
        DescribeAvailabilityZonesResponse zonesResponse = ec2.describeAvailabilityZones();
        for (AvailabilityZone zone : zonesResponse.availabilityZones()) {
            System.out.printf("Found Availability Zone %s " + "with status %s " + "in region %s", zone.zoneName(), zone.state(), zone.regionName());
            System.out.println();
        // snippet-end:[ec2.java2.describe_region_and_zones.avail_zone]
        }
    } catch (Ec2Exception e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : DescribeAvailabilityZonesResponse(software.amazon.awssdk.services.ec2.model.DescribeAvailabilityZonesResponse) Ec2Exception(software.amazon.awssdk.services.ec2.model.Ec2Exception) Region(software.amazon.awssdk.services.ec2.model.Region) AvailabilityZone(software.amazon.awssdk.services.ec2.model.AvailabilityZone) DescribeRegionsResponse(software.amazon.awssdk.services.ec2.model.DescribeRegionsResponse)

Aggregations

AvailabilityZone (software.amazon.awssdk.services.ec2.model.AvailabilityZone)1 DescribeAvailabilityZonesResponse (software.amazon.awssdk.services.ec2.model.DescribeAvailabilityZonesResponse)1 DescribeRegionsResponse (software.amazon.awssdk.services.ec2.model.DescribeRegionsResponse)1 Ec2Exception (software.amazon.awssdk.services.ec2.model.Ec2Exception)1 Region (software.amazon.awssdk.services.ec2.model.Region)1