//snippet-sourcedescription:[DescribeRegionsAndZones.java demonstrates how to get information about all the regions and zones from an EC2 client.]
//snippet-keyword:[SDK for Java 2.0]
//snippet-keyword:[Code Sample]
//snippet-service:[ec2]
//snippet-sourcetype:[full-example]
//snippet-sourcedate:[11/02/2020]
//snippet-sourceauthor:[soo-aws]
/*
 * Copyright 2010-2020 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_region_and_zones.complete]
// snippet-start:[ec2.java2.describe_region_and_zones.import]
import software.amazon.awssdk.services.ec2.Ec2Client;
import software.amazon.awssdk.services.ec2.model.DescribeRegionsResponse;
import software.amazon.awssdk.services.ec2.model.Region;
import software.amazon.awssdk.services.ec2.model.AvailabilityZone;
import software.amazon.awssdk.services.ec2.model.Ec2Exception;
import software.amazon.awssdk.services.ec2.model.DescribeAvailabilityZonesResponse;
// snippet-end:[ec2.java2.describe_region_and_zones.import]

/**
 * Describes all regions and zones
 */
public class DescribeRegionsAndZones {

    public static void main(String[] args) {
        // snippet-start:[ec2.java2.describe_region_and_zones.main]
        // snippet-start:[ec2.java2.describe_region_and_zones.client]
        Ec2Client ec2 = Ec2Client.create();
        // snippet-end:[ec2.java2.describe_region_and_zones.client]

        // 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) {
        e.getStackTrace();
    }
        // snippet-end:[ec2.java2.describe_region_and_zones.main]
    }
}

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

@@ -300,12 +300,10 @@
 te:%5B
-11/0
+2/
 2/20
@@ -336,10 +336,15 @@
 r:%5Bs
-oo
+cmacdon
 -aws
@@ -367,18 +367,8 @@
 ght 
-2010-2020 
 Amaz
@@ -1943,24 +1943,144 @@
 .client%5D%0D%0A%0D%0A
+        describeEC2RegionsAndZones(ec2);%0D%0A%0D%0A    %7D%0D%0A    public static void describeEC2RegionsAndZones( Ec2Client ec2) %7B%0D%0A
         // s
@@ -2349,24 +2349,28 @@
             
+    
 %22Found regio
@@ -2403,24 +2403,28 @@
             
+    
 %22with endpoi
@@ -2428,24 +2428,28 @@
 point %25s%22,%0D%0A
+    
             
@@ -2494,24 +2494,28 @@
             
+    
 region.endpo
@@ -2554,32 +2554,36 @@
 out.println();%0D%0A
+    
             // s
@@ -2631,32 +2631,36 @@
 _zones.region%5D%0D%0A
+    
         %7D%0D%0A%0D%0A   
@@ -2814,16 +2814,20 @@
         
+    
 ec2.desc
@@ -2984,24 +2984,28 @@
             
+    
 %22Found avail
@@ -3049,24 +3049,28 @@
             
+    
 %22with status
@@ -3106,16 +3106,20 @@
         
+   
+ 
 %22in regi
@@ -3123,24 +3123,28 @@
 egion %25s%22,%0D%0A
+    
             
@@ -3185,24 +3185,28 @@
             
+    
 zone.state()
@@ -3224,24 +3224,28 @@
             
+  
+  
 zone.regionN
@@ -3284,32 +3284,36 @@
 out.println();%0D%0A
+    
             // s
@@ -3373,32 +3373,36 @@
 _zone%5D%0D%0A        
+    
 %7D%0D%0A%0D%0A    %7D catch
@@ -3394,16 +3394,20 @@
 %0D%0A%0D%0A    
+ 
+   
 %7D catch 
@@ -3434,16 +3434,20 @@
         
+    
 e.getSta
@@ -3454,24 +3454,28 @@
 ckTrace();%0D%0A
+    
     %7D%0D%0A     

Update DescribeRegionsAndZones.java