本文整理匯總了Java中com.amazonaws.services.ec2.AmazonEC2Client.describeRegions方法的典型用法代碼示例。如果您正苦於以下問題:Java AmazonEC2Client.describeRegions方法的具體用法?Java AmazonEC2Client.describeRegions怎麽用?Java AmazonEC2Client.describeRegions使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.amazonaws.services.ec2.AmazonEC2Client
的用法示例。
在下文中一共展示了AmazonEC2Client.describeRegions方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getEndpointForRegion
import com.amazonaws.services.ec2.AmazonEC2Client; //導入方法依賴的package包/類
private static String getEndpointForRegion(AmazonEC2Client client, String regionName) {
requireNonNull(client, "client is null");
requireNonNull(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)));
}
示例2: regions
import com.amazonaws.services.ec2.AmazonEC2Client; //導入方法依賴的package包/類
@Override
@Cacheable(cacheNames = "cloudResourceRegionCache", key = "#cloudCredential?.id")
public CloudRegions regions(CloudCredential cloudCredential, Region region, Map<String, String> filters) throws Exception {
AmazonEC2Client ec2Client = awsClient.createAccess(cloudCredential);
Map<Region, List<AvailabilityZone>> regionListMap = new HashMap<>();
Map<Region, String> displayNames = new HashMap<>();
DescribeRegionsRequest describeRegionsRequest = new DescribeRegionsRequest();
DescribeRegionsResult describeRegionsResult = ec2Client.describeRegions(describeRegionsRequest);
String defaultRegion = awsZoneParameterDefault;
for (com.amazonaws.services.ec2.model.Region awsRegion : describeRegionsResult.getRegions()) {
if (region == null || Strings.isNullOrEmpty(region.value()) || awsRegion.getRegionName().equals(region.value())) {
DescribeAvailabilityZonesRequest describeAvailabilityZonesRequest = new DescribeAvailabilityZonesRequest();
ec2Client.setRegion(RegionUtils.getRegion(awsRegion.getRegionName()));
Filter filter = new Filter();
filter.setName("region-name");
List<String> list = new ArrayList<>();
list.add(awsRegion.getRegionName());
filter.setValues(list);
describeAvailabilityZonesRequest.withFilters(filter);
DescribeAvailabilityZonesResult describeAvailabilityZonesResult = ec2Client.describeAvailabilityZones(describeAvailabilityZonesRequest);
List<AvailabilityZone> tmpAz = new ArrayList<>();
for (com.amazonaws.services.ec2.model.AvailabilityZone availabilityZone : describeAvailabilityZonesResult.getAvailabilityZones()) {
tmpAz.add(availabilityZone(availabilityZone.getZoneName()));
}
regionListMap.put(region(awsRegion.getRegionName()), tmpAz);
DisplayName displayName = regionDisplayNames.get(region(awsRegion.getRegionName()));
if (displayName == null || Strings.isNullOrEmpty(displayName.value())) {
displayNames.put(region(awsRegion.getRegionName()), awsRegion.getRegionName());
} else {
displayNames.put(region(awsRegion.getRegionName()), displayName.value());
}
}
}
if (region != null && !Strings.isNullOrEmpty(region.value())) {
defaultRegion = region.value();
}
return new CloudRegions(regionListMap, displayNames, defaultRegion);
}