本文整理匯總了Java中com.amazonaws.services.ec2.AmazonEC2Client.setRegion方法的典型用法代碼示例。如果您正苦於以下問題:Java AmazonEC2Client.setRegion方法的具體用法?Java AmazonEC2Client.setRegion怎麽用?Java AmazonEC2Client.setRegion使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.amazonaws.services.ec2.AmazonEC2Client
的用法示例。
在下文中一共展示了AmazonEC2Client.setRegion方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: Ec2TagInstanceDiscovery
import com.amazonaws.services.ec2.AmazonEC2Client; //導入方法依賴的package包/類
protected Ec2TagInstanceDiscovery(AmazonEC2Client ec2Client) {
Preconditions.checkNotNull(ec2Client);
this.ec2Client = ec2Client;
Preconditions.checkState(!Strings.isNullOrEmpty(CLUSTER_TAG_KEY.get()), PROPERTY_NAME + " must be supplied!");
String regionName = DynamicPropertyFactory.getInstance().getStringProperty("turbine.region", "").get();
if(Strings.isNullOrEmpty(regionName)) {
Region currentRegion = Regions.getCurrentRegion();
if(currentRegion != null) {
regionName = currentRegion.getName();
} else {
regionName = "us-east-1";
}
}
ec2Client.setRegion(Region.getRegion(Regions.fromName(regionName)));
log.debug("Set the ec2 region to [{}]", regionName);
}
示例2: AsgTagInstanceDiscovery
import com.amazonaws.services.ec2.AmazonEC2Client; //導入方法依賴的package包/類
protected AsgTagInstanceDiscovery(AmazonAutoScalingClient asgClient, AmazonEC2Client ec2Client) {
Preconditions.checkNotNull(asgClient);
Preconditions.checkNotNull(ec2Client);
Preconditions.checkState(!Strings.isNullOrEmpty(CLUSTER_TAG_KEY.get()), TAG_PROPERTY_NAME + " must be supplied!");
this.asgClient = asgClient;
this.ec2Client = ec2Client;
String regionName = DynamicPropertyFactory.getInstance().getStringProperty("turbine.region", "").get();
if(Strings.isNullOrEmpty(regionName)) {
Region currentRegion = Regions.getCurrentRegion();
if(currentRegion != null) {
regionName = currentRegion.getName();
} else {
regionName = "us-east-1";
}
}
Region region = Region.getRegion(Regions.fromName(regionName));
ec2Client.setRegion(region);
asgClient.setRegion(region);
log.debug("Set the region to [{}]", region);
}
示例3: getClientForAccount
import com.amazonaws.services.ec2.AmazonEC2Client; //導入方法依賴的package包/類
private AmazonEC2Client getClientForAccount(final String accountId, final Region region) {
final AWSSecurityTokenServiceClient stsClient = new AWSSecurityTokenServiceClient(new ProfileCredentialsProvider());
final AssumeRoleRequest assumeRequest = new AssumeRoleRequest().withRoleArn(
"arn:aws:iam::ACCOUNT_ID:role/fullstop-role")
.withDurationSeconds(3600).withRoleSessionName(
"fullstop-role");
final AssumeRoleResult assumeResult = stsClient.assumeRole(assumeRequest);
final BasicSessionCredentials temporaryCredentials = new BasicSessionCredentials(
assumeResult.getCredentials()
.getAccessKeyId(), assumeResult.getCredentials().getSecretAccessKey(),
assumeResult.getCredentials().getSessionToken());
final AmazonEC2Client amazonEC2Client = new AmazonEC2Client(temporaryCredentials);
amazonEC2Client.setRegion(region);
return amazonEC2Client;
}
示例4: fetchEC2
import com.amazonaws.services.ec2.AmazonEC2Client; //導入方法依賴的package包/類
private void fetchEC2(final Region region) {
Path ec2Path = Paths.get(currentDir, "ec2");
ec2Path.toFile().mkdir();
AmazonEC2Client amazonEC2Client = new AmazonEC2Client();
amazonEC2Client.setRegion(region);
DescribeInstancesResult describeInstancesResult = amazonEC2Client.describeInstances();
List<Reservation> reservations = describeInstancesResult.getReservations();
for (Reservation reservation : reservations) {
List<Instance> instances = reservation.getInstances();
for (Instance instance : instances) {
System.out.println("instance id: " + instance.getInstanceId());
}
}
}
示例5: makeRegionalEc2Client
import com.amazonaws.services.ec2.AmazonEC2Client; //導入方法依賴的package包/類
/**
* Constructs an AmazonEC2Client and sets the region.
*/
public AmazonEC2Client makeRegionalEc2Client()
{
AWSCredentials credentials = new BasicAWSCredentials(awsAccessKeyId, awsSecretAccessKey);
AmazonEC2Client ec2 = new AmazonEC2Client(credentials);
ec2.setRegion(awsRegion);
return ec2;
}
示例6: run
import com.amazonaws.services.ec2.AmazonEC2Client; //導入方法依賴的package包/類
public void run() {
ImageViewer viewer = null;
AmazonEC2Client ec2Client = new AmazonEC2Client(clientConfiguration);
if (region != null) {
ec2Client.setRegion(Region.getRegion(Regions.fromName(region)));
}
while (true) {
try {
GetConsoleScreenshotResult result = ec2Client.getConsoleScreenshot(
new GetConsoleScreenshotRequest()
.withInstanceId(instanceId)
.withWakeUp(Boolean.TRUE)
);
byte[] imageData = Base64.getDecoder().decode(result.getImageData());
if (viewer == null) {
viewer = new ImageViewer(instanceId, imageData);
} else {
viewer.setImageData(imageData);
System.out.print(".");
}
Thread.sleep(interval * 1000);
} catch (Exception e) {
// Ignore it
System.out.print("x");
}
}
}
示例7: init
import com.amazonaws.services.ec2.AmazonEC2Client; //導入方法依賴的package包/類
private static void init() throws Exception {
/*
* The ProfileCredentialsProvider will return your [default]
* credential profile by reading from the credentials file located at
* (~/.aws/credentials).
*/
AWSCredentials credentials = null;
try {
credentials = new ProfileCredentialsProvider().getCredentials();
} catch (Exception e) {
throw new AmazonClientException(
"Cannot load the credentials from the credential profiles file. " +
"Please make sure that your credentials file is at the correct " +
"location (~/.aws/credentials), and is in valid format.",
e);
}
ec2 = new AmazonEC2Client(credentials);
sqs = new AmazonSQSClient(credentials);
Region usEast1 = Region.getRegion(Regions.US_EAST_1);
ec2.setRegion(usEast1);
sqs.setRegion(usEast1);
dynamoDB = new DynamoDBService(credentials);
}
示例8: gateways
import com.amazonaws.services.ec2.AmazonEC2Client; //導入方法依賴的package包/類
@Override
public CloudGateWays gateways(CloudCredential cloudCredential, Region region, Map<String, String> filters) throws Exception {
AmazonEC2Client ec2Client = awsClient.createAccess(cloudCredential);
Map<String, Set<CloudGateWay>> resultCloudGateWayMap = new HashMap<>();
CloudRegions regions = regions(cloudCredential, region, filters);
for (Map.Entry<Region, List<AvailabilityZone>> regionListEntry : regions.getCloudRegions().entrySet()) {
if (region == null || Strings.isNullOrEmpty(region.value()) || regionListEntry.getKey().value().equals(region.value())) {
ec2Client.setRegion(RegionUtils.getRegion(regionListEntry.getKey().value()));
DescribeInternetGatewaysRequest describeInternetGatewaysRequest = new DescribeInternetGatewaysRequest();
DescribeInternetGatewaysResult describeInternetGatewaysResult = ec2Client.describeInternetGateways(describeInternetGatewaysRequest);
Set<CloudGateWay> gateWays = new HashSet<>();
for (InternetGateway internetGateway : describeInternetGatewaysResult.getInternetGateways()) {
CloudGateWay cloudGateWay = new CloudGateWay();
cloudGateWay.setId(internetGateway.getInternetGatewayId());
cloudGateWay.setName(internetGateway.getInternetGatewayId());
List<String> vpcs = new ArrayList<>();
for (InternetGatewayAttachment internetGatewayAttachment : internetGateway.getAttachments()) {
vpcs.add(internetGatewayAttachment.getVpcId());
}
Map<String, Object> properties = new HashMap<>();
properties.put("attachment", vpcs);
cloudGateWay.setProperties(properties);
gateWays.add(cloudGateWay);
}
for (AvailabilityZone availabilityZone : regionListEntry.getValue()) {
resultCloudGateWayMap.put(availabilityZone.value(), gateWays);
}
}
}
return new CloudGateWays(resultCloudGateWayMap);
}
示例9: createAccess
import com.amazonaws.services.ec2.AmazonEC2Client; //導入方法依賴的package包/類
public AmazonEC2Client createAccess(AwsCredentialView awsCredential, String regionName) {
AmazonEC2Client client = isRoleAssumeRequired(awsCredential)
? new AmazonEC2Client(credentialClient.retrieveCachedSessionCredentials(awsCredential))
: new AmazonEC2Client(createAwsCredentials(awsCredential));
client.setRegion(RegionUtils.getRegion(regionName));
return client;
}
示例10: createEC2Client
import com.amazonaws.services.ec2.AmazonEC2Client; //導入方法依賴的package包/類
public static AmazonEC2Client createEC2Client(Region region) {
Preconditions.checkNotNull(region);
AmazonEC2Client client = new AmazonEC2Client(getCredentialProvider());
client.setRegion(region);
return client;
}
示例11: EC2
import com.amazonaws.services.ec2.AmazonEC2Client; //導入方法依賴的package包/類
public EC2(AWSCredentials credentials, Region region) {
ec2 = new AmazonEC2Client(credentials);
ec2.setRegion(region);
}
示例12: createAmazonEC2Client
import com.amazonaws.services.ec2.AmazonEC2Client; //導入方法依賴的package包/類
public AmazonEC2Client createAmazonEC2Client(AWSCredentials crendentials) {
AmazonEC2Client amazonEC2Client = new AmazonEC2Client(new SimpleAWSCredentialsProvider(crendentials));
amazonEC2Client.setRegion(region);
return amazonEC2Client;
}
示例13: 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);
}