@Override public List<String> getDefaultRacks() { // Get the fist 3 available zones in the region AmazonEC2 client = AmazonEC2ClientBuilder.standard() .withCredentials(credential.getAwsCredentialProvider()) .withRegion(getRegion()) .build(); 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; } return ImmutableList.copyOf(zone); }
protected AmazonEC2 getEc2Client() { return AmazonEC2ClientBuilder.standard() .withCredentials(provider.getAwsCredentialProvider()) .withRegion(instanceInfo.getRegion()) .build(); } }
@Override public String getAutoScalingGroup() { final AmazonEC2 client = AmazonEC2ClientBuilder.standard() .withCredentials(credential.getAwsCredentialProvider()) .withRegion(getRegion()) .build(); try { return new RetryableCallable<String>(15, 30000) { public String retriableCall() throws IllegalStateException { DescribeInstancesRequest desc = new DescribeInstancesRequest().withInstanceIds(getInstanceId()); DescribeInstancesResult res = client.describeInstances(desc); for (Reservation resr : res.getReservations()) { for (Instance ins : resr.getInstances()) { for (com.amazonaws.services.ec2.model.Tag tag : ins.getTags()) { if (tag.getKey().equals("aws:autoscaling:groupName")) return tag.getValue(); } } } throw new IllegalStateException("Couldn't determine ASG name"); } }.call(); } catch (Exception e) { logger.error("Failed to determine ASG name.", e); return null; } }
/** * Initializing the IP finder. */ private void initClients() { if (credsProvider == null || isNullOrEmpty(loadBalancerName) || isNullOrEmpty(region)) throw new IgniteSpiException("One or more configuration parameters are invalid [setCredentialsProvider=" + credsProvider + ", setRegion=" + region + ", setLoadBalancerName=" + loadBalancerName + "]"); if (amazonEC2Client == null) amazonEC2Client = AmazonEC2ClientBuilder.standard().withRegion(region).withCredentials(credsProvider) .build(); if (amazonELBClient == null) amazonELBClient = AmazonElasticLoadBalancingClientBuilder.standard().withRegion(region) .withCredentials(credsProvider).build(); }
public AMIMapper(String allocatedRegion) throws TestGridInfrastructureException { Path configFilePath = Paths.get(TestGridUtil.getTestGridHomePath(), TestGridConstants.TESTGRID_CONFIG_FILE); if (!Files.exists(configFilePath)) { throw new TestGridInfrastructureException( TestGridConstants.TESTGRID_CONFIG_FILE + " file not found." + " Unable to obtain AWS credentials. Check if the file exists in " + configFilePath.toFile().toString()); } this.region = allocatedRegion; amazonEC2 = AmazonEC2ClientBuilder.standard() .withCredentials(new PropertiesFileCredentialsProvider(configFilePath.toString())) .withRegion(region) .build(); }
try{ if(!skipRegions.contains(region.getName())){ ec2Client = AmazonEC2ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); List<VpnGateway> vpnGatewayList = ec2Client.describeVpnGateways().getVpnGateways();
public static AmazonEC2Client createEC2Client() { BasicCredentialsProvider credentials = BasicCredentialsProvider.standard(); AmazonEC2Client client = !credentials.isValid() ? null : (AmazonEC2Client) AmazonEC2ClientBuilder.standard() .withCredentials(credentials) .withRegion("eu-west-1") .build(); return client; }
try{ if(!skipRegions.contains(region.getName())){ ec2Client = AmazonEC2ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); DescribeSubnetsResult rslt = ec2Client.describeSubnets(); List<Subnet> subnetsTemp =rslt.getSubnets();
try{ if(!skipRegions.contains(region.getName())){ ec2Client = AmazonEC2ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); List<DhcpOptions> dhcpOptionsList = ec2Client.describeDhcpOptions().getDhcpOptions();
try{ if(!skipRegions.contains(region.getName())){ ec2Client = AmazonEC2ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); List<CustomerGateway> customerGatewayList = ec2Client.describeCustomerGateways().getCustomerGateways();
public static AmazonEC2Client createEC2Client() { BasicCredentialsProvider credentials = BasicCredentialsProvider.standard(); AmazonEC2Client client = !credentials.isValid() ? null : (AmazonEC2Client) AmazonEC2ClientBuilder.standard() .withCredentials(credentials) .withRegion("eu-west-1") .build(); return client; }
public AmazonEC2 produceAmazonEC2Client( @NonNull final String alias ){ final AmazonWebServiceConfiguration configuration = configurationProducer.configForService(alias); return AmazonEC2ClientBuilder.standard() .withClientConfiguration(this.configuration) .withCredentials( configuration.getIamPolicy() ) .withRegion( configuration.getRegion() ) .build(); } }
try{ if(!skipRegions.contains(region.getName())){ ec2Client = AmazonEC2ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); List<EgressOnlyInternetGateway> egressGatewayList = ec2Client.describeEgressOnlyInternetGateways(new DescribeEgressOnlyInternetGatewaysRequest()).getEgressOnlyInternetGateways();
AmazonEC2 loadEC2Client() { return AmazonEC2ClientBuilder.standard() .withCredentials( defaultCredentialFactory.loadCredentialProvider() ) .withRegion( identification.getRegion() ) .build(); }
AmazonEC2 createAmazonEC2Client(){ return AmazonEC2ClientBuilder.standard() .withClientConfiguration( clientConfiguration ) .withCredentials( configuration.getIamPolicy() ) .withRegion( configuration.getRegion() ) .build(); } }
/** * Constructs a new {@link Ec2ApiClient} that operates against a given AWS * region. * * @param awsCredentials * The AWS credentials used to connect to the AWS account. * @param region * The AWS region that this client operates against. * @param clientConfiguration * Any HTTP client configuration to customize API invocations. */ public Ec2ApiClient(AWSCredentials awsCredentials, String region, ClientConfiguration clientConfiguration) { // limit the time-to-live of the JVM's DNS cache (in seconds) java.security.Security.setProperty("networkaddress.cache.ttl", "60"); this.region = region; this.api = AmazonEC2ClientBuilder.standard().withRegion(region) .withCredentials(new AWSStaticCredentialsProvider(awsCredentials)).build(); }
private AwsInstanceManager(String region, String awsAccessKeyId, String awsSecretKey, AwsClientBuilder.EndpointConfiguration endpointConfiguration) { AmazonEC2ClientBuilder clientBuilder = AmazonEC2Client.builder().withCredentials(new AWSCredentialsProvider() { @Override public AWSCredentials getCredentials() { return new AWSCredentials() { @Override public String getAWSAccessKeyId() { return awsAccessKeyId; } @Override public String getAWSSecretKey() { return awsSecretKey; } }; } @Override public void refresh() { // No-op } }); if (endpointConfiguration == null) clientBuilder.withRegion(region); else clientBuilder.withEndpointConfiguration(endpointConfiguration); setEc2Client(clientBuilder.build()); }
/** * Delete the specified cluster if it exists. This will return after the initial request to delete the cluster * is completed. At this point, the cluster is likely not yet deleted, but in a deleting state. * * @param id the id of the cluster to delete */ public void deleteCluster(String id) { LOG.info("Deleting cluster {}.", id); client.terminateJobFlows(new TerminateJobFlowsRequest().withJobFlowIds(id)); AmazonEC2 ec2 = AmazonEC2ClientBuilder.standard() .withCredentials(emrConf.getCredentialsProvider()) .withRegion(emrConf.getRegion()) .build(); // named the keypair the same thing as the cluster id ec2.deleteKeyPair(new DeleteKeyPairRequest().withKeyName(id)); }
/** * Initializing the IP finder. */ private void initClients() { if (credsProvider == null || isNullOrEmpty(loadBalancerName) || isNullOrEmpty(region)) throw new IgniteSpiException("One or more configuration parameters are invalid [setCredentialsProvider=" + credsProvider + ", setRegion=" + region + ", setLoadBalancerName=" + loadBalancerName + "]"); if (amazonEC2Client == null) amazonEC2Client = AmazonEC2ClientBuilder.standard().withRegion(region).withCredentials(credsProvider) .build(); if (amazonELBClient == null) amazonELBClient = AmazonElasticLoadBalancingClientBuilder.standard().withRegion(region) .withCredentials(credsProvider).build(); }
/** * Creates a client for accessing Amazon EC2 service. * * @param awsParamsDto the AWS related parameters DTO that includes optional AWS credentials and proxy information * * @return the Amazon EC2 client */ @Cacheable(DaoSpringModuleConfig.HERD_CACHE_NAME) public AmazonEC2 getEc2Client(AwsParamsDto awsParamsDto) { // Get client configuration. ClientConfiguration clientConfiguration = awsHelper.getClientConfiguration(awsParamsDto); // If specified, use the AWS credentials passed in. if (StringUtils.isNotBlank(awsParamsDto.getAwsAccessKeyId())) { return AmazonEC2ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider( new BasicSessionCredentials(awsParamsDto.getAwsAccessKeyId(), awsParamsDto.getAwsSecretKey(), awsParamsDto.getSessionToken()))) .withClientConfiguration(clientConfiguration).withRegion(awsParamsDto.getAwsRegionName()).build(); } // Otherwise, use the default AWS credentials provider chain. else { return AmazonEC2ClientBuilder.standard().withClientConfiguration(clientConfiguration).withRegion(awsParamsDto.getAwsRegionName()).build(); } }