AWS SDK for Java
Developer Guide

Using Regions and Availability Zones

Important

This is a preview release and is not recommended for production environments.

Describing Regions

To list the regions available to your account, call the Ec2Client's describeRegions method. It returns a DescribeRegionsResponse. Call the returned object's regions method to get a list of Region objects that represent each region.

Imports

import software.amazon.awssdk.services.ec2.Ec2Client; import software.amazon.awssdk.services.ec2.model.DescribeRegionsResponse; import software.amazon.awssdk.services.ec2.model.Region;

Code

Ec2Client ec2 = Ec2Client.create(); DescribeRegionsResponse regions_response = ec2.describeRegions(); for(Region region : regions_response.regions()) { System.out.printf( "Found region %s " + "with endpoint %s", region.regionName(), region.endpoint()); System.out.println();

See the complete example on GitHub.

Describing Availability Zones

To list each availability zone available to your account, call the Ec2Client's describeAvailabilityZones method. It returns a DescribeAvailabilityZonesResponse. Call its availabilityZones method to get a list of AvailabilityZone objects that represent each availability zone.

Imports

import software.amazon.awssdk.services.ec2.Ec2Client; import software.amazon.awssdk.services.ec2.model.AvailabilityZone; import software.amazon.awssdk.services.ec2.model.DescribeAvailabilityZonesResponse;

Code

Ec2Client ec2 = Ec2Client.create(); DescribeAvailabilityZonesResponse zones_response = ec2.describeAvailabilityZones(); for(AvailabilityZone zone : zones_response.availabilityZones()) { System.out.printf( "Found availability zone %s " + "with status %s " + "in region %s", zone.zoneName(), zone.state(), zone.regionName());

See the complete example on GitHub.

More Information