Java Code Examples for com.amazonaws.services.ec2.AmazonEC2Client#setRegion()

The following examples show how to use com.amazonaws.services.ec2.AmazonEC2Client#setRegion() . 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: AwsSessionService.java    From Gatekeeper with Apache License 2.0 5 votes vote down vote up
public AmazonEC2Client getEC2Session(AWSEnvironment environment){
    BasicSessionCredentials creds = credentialCache.getUnchecked(environment);
    AmazonEC2Client ec2 = awsSessionFactory.createEC2Session(creds);
    ec2.setRegion(Region.getRegion(Regions.fromName(environment.getRegion())));
    return ec2;

}
 
Example 2
Source File: AwsPlatformResources.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
private DescribeAvailabilityZonesRequest getDescribeAvailabilityZonesRequest(AmazonEC2Client ec2Client, com.amazonaws.services.ec2.model.Region awsRegion) {
    DescribeAvailabilityZonesRequest describeAvailabilityZonesRequest = new DescribeAvailabilityZonesRequest();
    ec2Client.setRegion(RegionUtils.getRegion(awsRegion.getRegionName()));
    Filter filter = new Filter();
    filter.setName("region-name");
    Collection<String> list = new ArrayList<>();
    list.add(awsRegion.getRegionName());
    filter.setValues(list);
    describeAvailabilityZonesRequest.withFilters(filter);
    return describeAvailabilityZonesRequest;
}
 
Example 3
Source File: AwsPlatformResources.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Override
public CloudGateWays gateways(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
    AmazonEC2Client ec2Client = awsClient.createAccess(cloudCredential);

    Map<String, Set<CloudGateWay>> resultCloudGateWayMap = new HashMap<>();
    CloudRegions regions = regions(cloudCredential, region, filters, true);

    for (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());
                Collection<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);
}
 
Example 4
Source File: AwsClient.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
public AmazonEC2Client createAccess(AwsCredentialView awsCredential, String regionName) {
    AmazonEC2Client client = isRoleAssumeRequired(awsCredential) ?
            getAmazonEC2Client(createAwsSessionCredentialProvider(awsCredential)) :
            getAmazonEC2Client(createAwsCredentials(awsCredential));
    client.setRegion(RegionUtils.getRegion(regionName));
    return client;
}
 
Example 5
Source File: AwsClientFactory.java    From soundwave with Apache License 2.0 4 votes vote down vote up
public static AmazonEC2Client createEC2Client(Region region) {
  Preconditions.checkNotNull(region);
  AmazonEC2Client client = new AmazonEC2Client(getCredentialProvider());
  client.setRegion(region);
  return client;
}
 
Example 6
Source File: AmazonEC2ClientFactory.java    From sequenceiq-samples with Apache License 2.0 4 votes vote down vote up
public AmazonEC2Client createAmazonEC2Client(AWSCredentials crendentials) {
	AmazonEC2Client amazonEC2Client = new AmazonEC2Client(new SimpleAWSCredentialsProvider(crendentials));
	amazonEC2Client.setRegion(region);
	return amazonEC2Client;
}