use of software.amazon.awssdk.services.ec2.model.AvailabilityZone 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);
}
}
Aggregations