Menu
AWS SDK for Java
Developer Guide

Using Regions and Availability Zones

Describing Regions

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

Imports

Copy
import com.amazonaws.services.ec2.AmazonEC2; import com.amazonaws.services.ec2.AmazonEC2ClientBuilder; import com.amazonaws.services.ec2.model.DescribeRegionsResult; import com.amazonaws.services.ec2.model.Region;

Code

Copy
final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient(); DescribeRegionsResult regions_response = ec2.describeRegions(); for(Region region : regions_response.getRegions()) { System.out.printf( "Found region %s " + "with endpoint %s", region.getRegionName(), region.getEndpoint()); }

See the complete example.

Describing Availability Zones

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

Imports

Copy
import com.amazonaws.services.ec2.AmazonEC2; import com.amazonaws.services.ec2.AmazonEC2ClientBuilder; import com.amazonaws.services.ec2.model.DescribeRegionsResult; import com.amazonaws.services.ec2.model.Region;

Code

Copy
DescribeAvailabilityZonesResult zones_response = ec2.describeAvailabilityZones(); for(AvailabilityZone zone : zones_response.getAvailabilityZones()) { System.out.printf( "Found availability zone %s " + "with status %s " + "in region %s", zone.getZoneName(), zone.getState(), zone.getRegionName()); }

See the complete example.

More Information