Java Code Examples for com.amazonaws.services.ec2.AmazonEC2#describeAvailabilityZones()

The following examples show how to use com.amazonaws.services.ec2.AmazonEC2#describeAvailabilityZones() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RaigadConfiguration.java    From Raigad with Apache License 2.0 6 votes vote down vote up
/**
 * Get the fist 3 available zones in the region
 */
public void setDefaultRACList(String region) {
    AmazonEC2 client = new AmazonEC2Client(provider.getAwsCredentialProvider());
    client.setEndpoint("ec2." + region + ".amazonaws.com");
    DescribeAvailabilityZonesResult res = client.describeAvailabilityZones();
    List<String> zone = Lists.newArrayList();

    for (AvailabilityZone reg : res.getAvailabilityZones()) {
        if (reg.getState().equals("available")) {
            zone.add(reg.getZoneName());
        }
        if (zone.size() == 3) {
            break;
        }
    }
    DEFAULT_AVAILABILITY_ZONES = ImmutableList.copyOf(zone);
}
 
Example 2
Source File: DescribeRegionsAndZones.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args)
    {
        final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();

// snippet-start:[ec2.java1.describe_region_and_zones.regions]
        DescribeRegionsResult regions_response = ec2.describeRegions();

        for(Region region : regions_response.getRegions()) {
            System.out.printf(
                "Found region %s " +
                "with endpoint %s",
                region.getRegionName(),
                region.getEndpoint());
        }
// snippet-end:[ec2.java1.describe_region_and_zones.regions]

// snippet-start:[ec2.java1.describe_region_and_zones.zones]
        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());
        }
// snippet-end:[ec2.java1.describe_region_and_zones.zones]
    }
 
Example 3
Source File: AWSSdkClient.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
/***
 * Get availability zones in an Amazon AWS region
 *
 * @return List of availability zones
 */
public List<AvailabilityZone> getAvailabilityZones() {

  final AmazonEC2 amazonEC2 = getEc2Client();

  final DescribeAvailabilityZonesResult describeAvailabilityZonesResult = amazonEC2.describeAvailabilityZones();
  final List<AvailabilityZone> availabilityZones = describeAvailabilityZonesResult.getAvailabilityZones();
  LOGGER.info("Found: " + availabilityZones.size() + " availability zone");

  return availabilityZones;
}