Search in sources :

Example 11 with AvailabilityZone

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);
    }
}
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 (com.amazonaws.services.ec2.model.AvailabilityZone)10 DescribeAvailabilityZonesResult (com.amazonaws.services.ec2.model.DescribeAvailabilityZonesResult)6 ArrayList (java.util.ArrayList)3 AmazonEC2 (com.amazonaws.services.ec2.AmazonEC2)2 HashSet (java.util.HashSet)2 AmazonClientException (com.amazonaws.AmazonClientException)1 AmazonServiceException (com.amazonaws.AmazonServiceException)1 CreateVolumeRequest (com.amazonaws.services.ec2.model.CreateVolumeRequest)1 CreateVolumeResult (com.amazonaws.services.ec2.model.CreateVolumeResult)1 DescribeInstancesResult (com.amazonaws.services.ec2.model.DescribeInstancesResult)1 DescribeRegionsResult (com.amazonaws.services.ec2.model.DescribeRegionsResult)1 DescribeSecurityGroupsResult (com.amazonaws.services.ec2.model.DescribeSecurityGroupsResult)1 Instance (com.amazonaws.services.ec2.model.Instance)1 Region (com.amazonaws.services.ec2.model.Region)1 Reservation (com.amazonaws.services.ec2.model.Reservation)1 SecurityGroup (com.amazonaws.services.ec2.model.SecurityGroup)1 Subnet (com.amazonaws.services.ec2.model.Subnet)1 Volume (com.amazonaws.services.ec2.model.Volume)1 Bucket (com.amazonaws.services.s3.model.Bucket)1 ObjectListing (com.amazonaws.services.s3.model.ObjectListing)1