Example usage for com.amazonaws.services.ec2.model DescribeRegionsResult getRegions

List of usage examples for com.amazonaws.services.ec2.model DescribeRegionsResult getRegions

Introduction

In this page you can find the example usage for com.amazonaws.services.ec2.model DescribeRegionsResult getRegions.

Prototype


public java.util.List<Region> getRegions() 

Source Link

Document

Information about the Regions.

Usage

From source file:aws.example.ec2.DescribeRegionsAndZones.java

License:Open Source License

public static void main(String[] args) {
    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());/*from   w ww.j a  v  a 2s .co  m*/
    }

    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());
    }
}

From source file:com.axemblr.yab.YaB.java

License:Apache License

/**
 * Constructs a new YaB client by fetching credentials in this order:
 * <p>/*  w w  w  .j av  a  2s. c o m*/
 * - Environment Variables - AWS_ACCESS_KEY_ID and AWS_SECRET_KEY
 * - Java System Properties - aws.accessKeyId and aws.secretKey
 * - Instance profile credentials delivered through the Amazon EC2 metadata service
 * </p>
 */
public static YaB createWithEnvironmentCredentials(String region) {
    AmazonEC2Client client = new AmazonEC2Client();

    boolean regionFound = false;
    DescribeRegionsResult result = client.describeRegions();
    for (Region candidate : result.getRegions()) {
        if (candidate.getRegionName().equals(region)) {
            client.setEndpoint(candidate.getEndpoint());
            regionFound = true;
            break;
        }
    }

    if (!regionFound) {
        throw new IllegalArgumentException("No region found with this name: " + region);
    }

    return new YaB(client);
}

From source file:com.cloudera.director.aws.ec2.EC2Provider.java

License:Apache License

/**
 * Returns the endpoint URL for the specified region.
 *
 * @param client     the EC2 client/*from  www. j  a v  a2s .c om*/
 * @param regionName the desired region
 * @return the endpoint URL for the specified region
 * @throws IllegalArgumentException if the endpoint cannot be determined
 */
private static String getEndpointForRegion(AmazonEC2Client client, String regionName) {
    checkNotNull(client, "client is null");
    checkNotNull(regionName, "regionName is null");

    LOG.info(">> Describing all regions to find endpoint for '{}'", regionName);

    DescribeRegionsResult result = client.describeRegions();
    List<String> regions = Lists.newArrayListWithExpectedSize(result.getRegions().size());

    for (Region candidate : result.getRegions()) {
        regions.add(candidate.getRegionName());

        if (candidate.getRegionName().equals(regionName)) {
            LOG.info("<< Found endpoint '{}' for region '{}'", candidate.getEndpoint(), regionName);

            return candidate.getEndpoint();
        }
    }

    throw new IllegalArgumentException(String.format(
            "Unable to find an endpoint for region '%s'. " + "Choose one of the following regions: %s",
            regionName, Joiner.on(", ").join(regions)));
}

From source file:com.noctarius.hazelcast.aws.HazelcastAwsDiscoveryStrategy.java

License:Open Source License

private Map<String, String> buildRegionLookup(AmazonEC2Client client) {
    Map<String, String> regionLookup = new HashMap<String, String>();

    DescribeRegionsResult regionsResult = client.describeRegions();
    for (Region region : regionsResult.getRegions()) {
        regionLookup.put(region.getRegionName(), region.getEndpoint());
    }/*ww w . j  av  a 2s .  co  m*/
    return Collections.unmodifiableMap(regionLookup);
}

From source file:com.norbl.cbp.ppe.AmiDescription.java

License:Open Source License

public static Region getRegion(AmazonEC2Client ec2Client, String amiID) {

    DescribeRegionsResult rr = ec2Client.describeRegions();
    for (Region reg : rr.getRegions()) {
        ec2Client.setEndpoint(reg.getEndpoint());
        if (hasAmi(ec2Client, amiID)) {
            return (reg);
        }//from  w w w .j  av a  2  s.  c  o  m
    }
    // Reset the endpoint to the default
    ec2Client.setEndpoint("ec2.amazonaws.com");

    return (null);

}

From source file:de.fischer.thotti.ec2.clients.EC2ExecutorITHelper.java

License:Apache License

public void retrieveRegions() {
    AmazonEC2Client awsClient = getAmazonClient();

    DescribeRegionsResult regionsResult = awsClient.describeRegions();

    awsRegions = regionsResult.getRegions();
}

From source file:de.fischer.thotti.ec2.clients.EC2InternalClient.java

License:Apache License

private void retrieveAWSRegionInformation() throws AWSCommunicationException {
    try {/*www  .j a v a 2s . com*/
        DescribeRegionsResult result = amazonEC2Client.describeRegions();
        awsRegions = result.getRegions();
    } catch (AmazonServiceException ase) {
        handleAmazonServiceException(ase);
    }

    if (logger.isDebugEnabled())
        for (Region r : awsRegions) {
            logger.debug("Found the following region '{}'.", new Object[] { r.getRegionName() });
        }
}

From source file:ec2.DescribeRegionsAndZones.java

License:Open Source License

public static void main(String[] args) {

    final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();

    DescribeRegionsResult response = ec2.describeRegions();

    for (Region region : response.getRegions()) {
        System.out.printf("Found region %s with endpoint %s", region.getRegionName(), region.getEndpoint());
    }//from   w w  w  .  j av a2 s.c  o  m

    DescribeAvailabilityZonesResult describeAvailabilityZonesResponse = ec2.describeAvailabilityZones();

    for (AvailabilityZone zone : describeAvailabilityZonesResponse.getAvailabilityZones()) {
        System.out.printf("Found availability zone %s with status %s in region %s", zone.getRegionName(),
                zone.getState(), zone.getRegionName());
    }
}

From source file:io.macgyver.plugin.cloud.aws.scanner.RegionScanner.java

License:Apache License

@Override
public void scan(Region region) {

    GraphNodeGarbageCollector gc = newGarbageCollector().region(region).label("AwsRegion");

    AmazonEC2Client c = getAWSServiceClient().createEC2Client(region);

    DescribeRegionsResult result = c.describeRegions();
    result.getRegions().forEach(it -> {
        try {/* w ww  .  j  a  va2 s  .c o m*/
            ObjectNode n = convertAwsObject(it, region);

            n.remove("aws_account");
            String cypher = "merge (x:AwsRegion {aws_regionName:{aws_regionName}}) set x+={props}  remove x.aws_region,x.aws_account set x.updateTs=timestamp() return x";

            NeoRxClient neoRx = getNeoRxClient();
            Preconditions.checkNotNull(neoRx);

            neoRx.execCypher(cypher, "aws_regionName", n.path("aws_regionName").asText(), "aws_region",
                    n.path("aws_region").asText(), "props", n).forEach(gc.MERGE_ACTION);

        } catch (RuntimeException e) {
            logger.warn("problem scanning regions", e);
        }
    });

    gc.invoke();

}

From source file:net.firejack.aws.web.controller.AWSController.java

License:Apache License

@ResponseBody
@RequestMapping(value = "auth", method = RequestMethod.POST)
public List<Dropdown> auth(@RequestBody Auth auth) {
    if (!auth.isValid())
        throw new AmazonServiceException("Access or Secret Key is empty");

    if (amazonEC2 != null)
        amazonEC2.shutdown();/*from w  w w .j  a v  a  2  s  .  c om*/

    amazonEC2 = new AmazonEC2Client(new BasicAWSCredentials(auth.getAccessKey(), auth.getSecretKey()));

    DescribeRegionsResult result = amazonEC2.describeRegions();
    List<Region> resultRegions = result.getRegions();

    List<Dropdown> regions = new ArrayList<Dropdown>(resultRegions.size());
    for (Region region : resultRegions)
        regions.add(new Dropdown(region.getRegionName(), region.getEndpoint()));

    return regions;
}