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

The following examples show how to use com.amazonaws.services.ec2.AmazonEC2#setEndpoint() . 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: AmazonAwsClientFactory.java    From primecloud-controller with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public AmazonEC2 createEc2Client(String awsAccessId, String awsSecretKey) {
    AWSCredentials credentials = new BasicAWSCredentials(awsAccessId, awsSecretKey);
    ClientConfiguration configuration = createConfiguration();

    AmazonEC2 client = new AmazonEC2Client(credentials, configuration);

    if (host != null) {
        client.setEndpoint(AmazonEC2.ENDPOINT_PREFIX + "." + host);
    }

    client = new ExceptionHandleAwsClientWrapper().wrap(client);

    return client;
}
 
Example 2
Source File: RaigadConfiguration.java    From Raigad with Apache License 2.0 6 votes vote down vote up
/**
 * Get the fist 3 available zones in the region
 */
public void setDefaultRACList(String region) {
    AmazonEC2 client = new AmazonEC2Client(provider.getAwsCredentialProvider());
    client.setEndpoint("ec2." + region + ".amazonaws.com");
    DescribeAvailabilityZonesResult res = client.describeAvailabilityZones();
    List<String> zone = Lists.newArrayList();

    for (AvailabilityZone reg : res.getAvailabilityZones()) {
        if (reg.getState().equals("available")) {
            zone.add(reg.getZoneName());
        }
        if (zone.size() == 3) {
            break;
        }
    }
    DEFAULT_AVAILABILITY_ZONES = ImmutableList.copyOf(zone);
}
 
Example 3
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 4
Source File: Ec2IaasHandler.java    From roboconf-platform with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a client for EC2.
 * @param targetProperties the target properties (not null)
 * @return a non-null client
 * @throws TargetException if properties are invalid
 */
public static AmazonEC2 createEc2Client( Map<String,String> targetProperties ) throws TargetException {

	parseProperties( targetProperties );

	// Configure the IaaS client
	AWSCredentials credentials = new BasicAWSCredentials(
			targetProperties.get(Ec2Constants.EC2_ACCESS_KEY),
			targetProperties.get(Ec2Constants.EC2_SECRET_KEY));

	AmazonEC2 ec2 = new AmazonEC2Client( credentials );
	ec2.setEndpoint( targetProperties.get(Ec2Constants.EC2_ENDPOINT ));

	return ec2;
}
 
Example 5
Source File: SetVPCSecurityGroupID.java    From Raigad with Apache License 2.0 4 votes vote down vote up
private AmazonEC2 getEc2Client() {
    AmazonEC2 client = new AmazonEC2Client(provider.getAwsCredentialProvider());
    client.setEndpoint("ec2." + config.getDC() + ".amazonaws.com");
    return client;
}
 
Example 6
Source File: AWSMembership.java    From Raigad with Apache License 2.0 4 votes vote down vote up
protected AmazonEC2 getEc2Client() {
    AmazonEC2 client = new AmazonEC2Client(provider.getAwsCredentialProvider());
    client.setEndpoint("ec2." + config.getDC() + ".amazonaws.com");
    return client;
}