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

The following examples show how to use com.amazonaws.services.ec2.AmazonEC2#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: KinesisConnectorExecutor.java    From amazon-kinesis-connectors with Apache License 2.0 6 votes vote down vote up
/**
 * Helper method to create Elasticsearch cluster at set correct endpoint.
 */
private void createElasticsearchCluster() {
    // Create stack if not already up
    AmazonCloudFormation cloudFormationClient = new AmazonCloudFormationClient(config.AWS_CREDENTIALS_PROVIDER);
    cloudFormationClient.setRegion(RegionUtils.getRegion(config.REGION_NAME));
    CloudFormationUtils.createStackIfNotExists(cloudFormationClient, config);

    // Update the elasticsearch endpoint to use endpoint in created cluster
    AmazonEC2 ec2Client = new AmazonEC2Client(config.AWS_CREDENTIALS_PROVIDER);
    ec2Client.setRegion(RegionUtils.getRegion(config.REGION_NAME));
    config.ELASTICSEARCH_ENDPOINT =
            EC2Utils.getEndpointForFirstActiveInstanceWithTag(ec2Client,
                    EC2_ELASTICSEARCH_FILTER_NAME,
                    EC2_ELASTICSEARCH_FILTER_VALUE);
    if (config.ELASTICSEARCH_ENDPOINT == null || config.ELASTICSEARCH_ENDPOINT.isEmpty()) {
        throw new RuntimeException("Could not find active Elasticsearch endpoint from cluster.");
    }
}
 
Example 2
Source File: AwsEc2ServiceImpl.java    From crate with Apache License 2.0 6 votes vote down vote up
private AmazonEC2 buildClient(Ec2ClientSettings clientSettings) {
    final AWSCredentialsProvider credentials = buildCredentials(LOGGER, clientSettings);
    final ClientConfiguration configuration = buildConfiguration(LOGGER, clientSettings);
    final AmazonEC2 client = buildClient(credentials, configuration);
    if (Strings.hasText(clientSettings.endpoint)) {
        LOGGER.debug("using explicit ec2 endpoint [{}]", clientSettings.endpoint);
        client.setEndpoint(clientSettings.endpoint);
    } else {
        Region currentRegion = Regions.getCurrentRegion();
        if (currentRegion != null) {
            LOGGER.debug("using ec2 region [{}]", currentRegion);
            client.setRegion(currentRegion);
        }
    }
    return client;
}
 
Example 3
Source File: MvcConfiguration.java    From aws-codedeploy-sample-tomcat with Apache License 2.0 4 votes vote down vote up
@Bean
public AmazonEC2 ec2() {
    final AmazonEC2 client = new AmazonEC2Client();
    client.setRegion(region);
    return client;
}
 
Example 4
Source File: Ec2Utils.java    From pacbot with Apache License 2.0 3 votes vote down vote up
/**
    * Gets the vpcs for region.
    *
    * @param ec2ServiceClient the ec 2 service client
    * @param region the region
    * @param request the request
    * @return the vpcs for region
    */
public static List<Vpc> getVpcsForRegion(AmazonEC2 ec2ServiceClient,
		Region region, DescribeVpcsRequest request) {
	ec2ServiceClient.setRegion(region);
	DescribeVpcsResult describeVpcsResult =  ec2ServiceClient.describeVpcs(request);
	return  describeVpcsResult.getVpcs();
	
}
 
Example 5
Source File: Ec2Utils.java    From pacbot with Apache License 2.0 3 votes vote down vote up
/**
 * Gets the subnets for region.
 *
 * @param ec2ServiceClient the ec 2 service client
 * @param region the region
 * @param describeSubnetsRequest the describe subnets request
 * @return the subnets for region
 */
public static List<Subnet> getSubnetsForRegion(AmazonEC2 ec2ServiceClient,
		Region region, DescribeSubnetsRequest describeSubnetsRequest) {
	ec2ServiceClient.setRegion(region);
	DescribeSubnetsResult describeSubnetsResult = ec2ServiceClient.describeSubnets(describeSubnetsRequest);
	return describeSubnetsResult.getSubnets();
}