com.amazonaws.services.rds.AmazonRDSClient Java Examples

The following examples show how to use com.amazonaws.services.rds.AmazonRDSClient. 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: AmazonRdsDatabaseAutoConfigurationTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Bean
AmazonRDSClient amazonRDS() {
	AmazonRDSClient client = Mockito.mock(AmazonRDSClient.class);
	when(client.describeDBInstances(
			new DescribeDBInstancesRequest().withDBInstanceIdentifier("test")))
					.thenReturn(new DescribeDBInstancesResult().withDBInstances(
							new DBInstance().withDBInstanceStatus("available")
									.withDBName("test")
									.withDBInstanceIdentifier("test")
									.withEngine("mysql")
									.withMasterUsername("admin")
									.withEndpoint(new Endpoint()
											.withAddress("localhost")
											.withPort(3306))
									.withReadReplicaDBInstanceIdentifiers(
											"read1")));
	return client;
}
 
Example #2
Source File: AmazonRdsInstanceConfigurationTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Bean
AmazonRDS amazonRDS() {
	AmazonRDSClient client = Mockito.mock(AmazonRDSClient.class);
	when(client.describeDBInstances(
			new DescribeDBInstancesRequest().withDBInstanceIdentifier("test")))
					.thenReturn(new DescribeDBInstancesResult().withDBInstances(
							new DBInstance().withDBInstanceStatus("available")
									.withDBName("test")
									.withDBInstanceIdentifier("test")
									.withEngine("mysql")
									.withMasterUsername("admin")
									.withEndpoint(new Endpoint()
											.withAddress("localhost")
											.withPort(3306))
									.withReadReplicaDBInstanceIdentifiers(
											"read1")));
	return client;
}
 
Example #3
Source File: AmazonRdsInstanceConfigurationTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Bean
AmazonRDS amazonRDS() {
	AmazonRDSClient client = Mockito.mock(AmazonRDSClient.class);
	when(client.describeDBInstances(
			new DescribeDBInstancesRequest().withDBInstanceIdentifier("test")))
					.thenReturn(new DescribeDBInstancesResult().withDBInstances(
							new DBInstance().withDBInstanceStatus("available")
									.withDBName("test")
									.withDBInstanceIdentifier("test")
									.withEngine("mysql")
									.withMasterUsername("admin")
									.withEndpoint(new Endpoint()
											.withAddress("localhost")
											.withPort(3306))
									.withReadReplicaDBInstanceIdentifiers(
											"read1")));
	return client;
}
 
Example #4
Source File: AmazonRdsInstanceConfigurationTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Bean
AmazonRDS amazonRDS() {
	AmazonRDSClient client = Mockito.mock(AmazonRDSClient.class);
	when(client.describeDBInstances(
			new DescribeDBInstancesRequest().withDBInstanceIdentifier("test")))
					.thenReturn(new DescribeDBInstancesResult().withDBInstances(
							new DBInstance().withDBInstanceStatus("available")
									.withDBName("test")
									.withDBInstanceIdentifier("test")
									.withEngine("mysql")
									.withMasterUsername("admin")
									.withEndpoint(new Endpoint()
											.withAddress("localhost")
											.withPort(3306))
									.withReadReplicaDBInstanceIdentifiers(
											"read1")));
	return client;
}
 
Example #5
Source File: AmazonRdsInstanceConfigurationTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Bean
AmazonRDS amazonRDS() {
	AmazonRDSClient client = Mockito.mock(AmazonRDSClient.class);
	when(client.describeDBInstances(
			new DescribeDBInstancesRequest().withDBInstanceIdentifier("test")))
					.thenReturn(new DescribeDBInstancesResult().withDBInstances(
							new DBInstance().withDBInstanceStatus("available")
									.withDBName("test")
									.withDBInstanceIdentifier("test")
									.withEngine("mysql")
									.withMasterUsername("admin")
									.withEndpoint(new Endpoint()
											.withAddress("localhost")
											.withPort(3306))
									.withReadReplicaDBInstanceIdentifiers(
											"read1")));
	return client;
}
 
Example #6
Source File: AmazonRdsInstanceConfigurationTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Bean
AmazonRDS amazonRDS() {
	AmazonRDSClient client = Mockito.mock(AmazonRDSClient.class);
	when(client.describeDBInstances(
			new DescribeDBInstancesRequest().withDBInstanceIdentifier("test")))
					.thenReturn(new DescribeDBInstancesResult().withDBInstances(
							new DBInstance().withDBInstanceStatus("available")
									.withDBName("test")
									.withDBInstanceIdentifier("test")
									.withEngine("mysql")
									.withMasterUsername("admin")
									.withEndpoint(new Endpoint()
											.withAddress("localhost")
											.withPort(3306))
									.withReadReplicaDBInstanceIdentifiers(
											"read1")));
	return client;
}
 
Example #7
Source File: BeanstalkConnector.java    From cloudml with GNU Lesser General Public License v3.0 5 votes vote down vote up
public BeanstalkConnector(String login, String pass, String region) {
    awsCredentials = new BasicAWSCredentials(login, pass);
    beanstalkClient = new AWSElasticBeanstalkClient(awsCredentials);
    this.beanstalkEndpoint = String.format("elasticbeanstalk.%s.amazonaws.com", region);
    beanstalkClient.setEndpoint(beanstalkEndpoint);

    this.rdsEndpoint = String.format("rds.%s.amazonaws.com", region);
    rdsClient = new AmazonRDSClient(awsCredentials);
    rdsClient.setEndpoint(rdsEndpoint);

    this.sqsEndpoint = String.format("sqs.%s.amazonaws.com", region);
    sqsClient=new AmazonSQSAsyncClient(awsCredentials);
    sqsClient.setEndpoint(this.sqsEndpoint);
}
 
Example #8
Source File: RdsLookupService.java    From Gatekeeper with Apache License 2.0 5 votes vote down vote up
public Optional<DBCluster> getPrimaryClusterForGlobalCluster(AWSEnvironment environment, String globalClusterId){
    AmazonRDSClient amazonRDSClient = awsSessionService.getRDSSession(environment);
    GlobalCluster theCluster = amazonRDSClient.describeGlobalClusters(
            new DescribeGlobalClustersRequest().withGlobalClusterIdentifier(globalClusterId)
    ).getGlobalClusters().get(0);

    return Optional.of(amazonRDSClient.describeDBClusters(new DescribeDBClustersRequest()
            .withFilters(
                    new Filter()
                            .withName("db-cluster-id")
                            .withValues(getPrimaryCluster(theCluster).getDBClusterArn())))
            .getDBClusters().get(0));
}
 
Example #9
Source File: AmazonRdsDatabaseAutoConfigurationTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Bean
AmazonRDS amazonRDS() {
	AmazonRDSClient client = Mockito.mock(AmazonRDSClient.class);
	when(client.describeDBInstances(
			new DescribeDBInstancesRequest().withDBInstanceIdentifier("test")))
					.thenReturn(new DescribeDBInstancesResult().withDBInstances(
							new DBInstance().withDBInstanceStatus("available")
									.withDBName("test")
									.withDBInstanceIdentifier("test")
									.withEngine("mysql")
									.withMasterUsername("admin")
									.withEndpoint(new Endpoint()
											.withAddress("localhost")
											.withPort(3306))
									.withReadReplicaDBInstanceIdentifiers(
											"read1")));
	when(client.describeDBInstances(
			new DescribeDBInstancesRequest().withDBInstanceIdentifier("read1")))
					.thenReturn(new DescribeDBInstancesResult().withDBInstances(
							new DBInstance().withDBInstanceStatus("available")
									.withDBName("read1")
									.withDBInstanceIdentifier("read1")
									.withEngine("mysql")
									.withMasterUsername("admin")
									.withEndpoint(new Endpoint()
											.withAddress("localhost")
											.withPort(3306))));
	return client;
}
 
Example #10
Source File: AmazonRdsDatabaseAutoConfigurationTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Bean
AmazonRDS amazonRDS() {
	AmazonRDSClient client = Mockito.mock(AmazonRDSClient.class);
	when(client.describeDBInstances(
			new DescribeDBInstancesRequest().withDBInstanceIdentifier("test")))
					.thenReturn(new DescribeDBInstancesResult().withDBInstances(
							new DBInstance().withDBInstanceStatus("available")
									.withDBName("test")
									.withDBInstanceIdentifier("test")
									.withEngine("mysql")
									.withMasterUsername("admin")
									.withEndpoint(new Endpoint()
											.withAddress("localhost")
											.withPort(3306))));
	when(client.describeDBInstances(new DescribeDBInstancesRequest()
			.withDBInstanceIdentifier("anotherOne")))
					.thenReturn(new DescribeDBInstancesResult().withDBInstances(
							new DBInstance().withDBInstanceStatus("available")
									.withDBName("test")
									.withDBInstanceIdentifier("anotherOne")
									.withEngine("mysql")
									.withMasterUsername("admin")
									.withEndpoint(new Endpoint()
											.withAddress("localhost")
											.withPort(3306))));
	return client;
}
 
Example #11
Source File: AmazonRdsInstanceConfigurationTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Bean
AmazonRDS amazonRDS() {
	AmazonRDSClient client = Mockito.mock(AmazonRDSClient.class);
	when(client.describeDBInstances(
			new DescribeDBInstancesRequest().withDBInstanceIdentifier("test")))
					.thenReturn(new DescribeDBInstancesResult().withDBInstances(
							new DBInstance().withDBInstanceStatus("available")
									.withDBName("test")
									.withDBInstanceIdentifier("test")
									.withEngine("mysql")
									.withMasterUsername("admin")
									.withEndpoint(new Endpoint()
											.withAddress("localhost")
											.withPort(3306))
									.withReadReplicaDBInstanceIdentifiers(
											"read1")));
	when(client.describeDBInstances(
			new DescribeDBInstancesRequest().withDBInstanceIdentifier("read1")))
					.thenReturn(new DescribeDBInstancesResult().withDBInstances(
							new DBInstance().withDBInstanceStatus("available")
									.withDBName("read1")
									.withDBInstanceIdentifier("read1")
									.withEngine("mysql")
									.withMasterUsername("admin")
									.withEndpoint(new Endpoint()
											.withAddress("localhost")
											.withPort(3306))));
	return client;
}
 
Example #12
Source File: FetchRdsJobTest.java    From fullstop with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    this.clientProviderMock = mock(ClientProvider.class);
    this.jobsPropertiesMock = mock(JobsProperties.class);
    this.violationSinkMock = mock(ViolationSink.class);
    this.amazonRDSClientMock = mock(AmazonRDSClient.class);
    this.accountIdSupplierMock = mock(AccountIdSupplier.class);
    this.exceptionHandlerMock = mock(JobExceptionHandler.class);

    when(accountIdSupplierMock.get()).thenReturn(newHashSet("54321"));

    // Jobsproperties
    when(jobsPropertiesMock.getWhitelistedRegions()).thenReturn(newArrayList("eu-west-1"));

    // Dbinstances
    final Endpoint endpoint = new Endpoint();
    endpoint.setAddress("aws.db.cn");
    final Endpoint endpoint2 = new Endpoint();
    endpoint2.setAddress("aws.db2.cn");
    final DBInstance dbInstance1 = new DBInstance();
    dbInstance1.setPubliclyAccessible(true);
    dbInstance1.setEndpoint(endpoint);
    final DBInstance dbInstance2 = new DBInstance();
    dbInstance2.setPubliclyAccessible(false);
    dbInstance2.setEndpoint(endpoint);
    final DBInstance dbInstance3 = new DBInstance();
    dbInstance3.setPubliclyAccessible(true);
    dbInstance3.setEndpoint(endpoint2);
    describeDBInstancesResultMock = new DescribeDBInstancesResult();
    describeDBInstancesResultMock.setDBInstances(newArrayList(dbInstance1, dbInstance2, dbInstance3));

    // clientprovider
    when(clientProviderMock.getClient(any(), any(String.class), any(Region.class))).thenReturn(amazonRDSClientMock);

}
 
Example #13
Source File: FetchRdsJob.java    From fullstop with Apache License 2.0 5 votes vote down vote up
@Scheduled(fixedRate = 300_000)
public void run() {
    for (final String accountId : allAccountIds.get()) {
        for (final String region : jobsProperties.getWhitelistedRegions()) {
            try {
                final AmazonRDSClient amazonRDSClient = clientProvider.getClient(AmazonRDSClient.class, accountId,
                        Region.getRegion(Regions.fromName(region)));

                Optional<String> marker = Optional.empty();

                do {
                    final DescribeDBInstancesRequest request = new DescribeDBInstancesRequest();
                    marker.ifPresent(request::setMarker);
                    final DescribeDBInstancesResult result = amazonRDSClient.describeDBInstances(request);
                    marker = Optional.ofNullable(trimToNull(result.getMarker()));

                    result.getDBInstances().stream()
                            .filter(DBInstance::getPubliclyAccessible)
                            .filter(dbInstance -> dbInstance.getEndpoint() != null)
                            .forEach(dbInstance -> {
                                final Map<String, Object> metadata = newHashMap();
                                metadata.put("unsecuredDatabase", dbInstance.getEndpoint().getAddress());
                                metadata.put("errorMessages", "Unsecured Database! Your DB can be reached from outside");
                                writeViolation(accountId, region, metadata, dbInstance.getEndpoint().getAddress());

                            });

                } while (marker.isPresent());

            } catch (final Exception e) {
                jobExceptionHandler.onException(e, ImmutableMap.of(
                        "job", this.getClass().getSimpleName(),
                        "aws_account_id", accountId,
                        "aws_region", region));
            }
        }
    }
}
 
Example #14
Source File: RdsLookupService.java    From Gatekeeper with Apache License 2.0 5 votes vote down vote up
private List<GlobalCluster> getGlobalClusters(AmazonRDSClient amazonRDSClient) {
    DescribeGlobalClustersResult describeGlobalClustersResult = amazonRDSClient.describeGlobalClusters(new DescribeGlobalClustersRequest());
    List<GlobalCluster> globalClusters = new ArrayList<>(describeGlobalClustersResult.getGlobalClusters());
    while(describeGlobalClustersResult.getMarker() != null){
        globalClusters.addAll(describeGlobalClustersResult.getGlobalClusters());
        amazonRDSClient.describeGlobalClusters(new DescribeGlobalClustersRequest()
                .withMarker(describeGlobalClustersResult.getMarker()));
    }

    return globalClusters;
}
 
Example #15
Source File: RdsLookupService.java    From Gatekeeper with Apache License 2.0 5 votes vote down vote up
private List<GatekeeperRDSInstance> loadInstances(AWSEnvironment environment, Predicate<? super DBInstance> filter) {
    logger.info("Refreshing RDS Instance Data");
    long startTime = System.currentTimeMillis();
    DescribeDBInstancesRequest describeDBInstancesRequest = new DescribeDBInstancesRequest()
            .withFilters(new Filter().withName("engine").withValues("postgres", "mysql", "oracle-se1", "oracle-se2"));
    List<String> securityGroupIds = sgLookupService.fetchSgsForAccountRegion(environment);
    AmazonRDSClient amazonRDSClient = awsSessionService.getRDSSession(environment);
    DescribeDBInstancesResult result = amazonRDSClient.describeDBInstances(describeDBInstancesRequest);

    List<GatekeeperRDSInstance> gatekeeperRDSInstances = loadToGatekeeperRDSInstance(environment, amazonRDSClient,
            result.getDBInstances()
                    .stream()
                    .filter(filter)
                    .collect(Collectors.toList()), securityGroupIds);

    //At a certain point (Usually ~100 instances) amazon starts paging the rds results, so we need to get each page, which is keyed off by a marker.
    while(result.getMarker() != null) {
        result = amazonRDSClient.describeDBInstances(describeDBInstancesRequest.withMarker(result.getMarker()));
        gatekeeperRDSInstances.addAll(loadToGatekeeperRDSInstance(environment, amazonRDSClient,
                result.getDBInstances()
                        .stream()
                        .filter(filter)
                        .collect(Collectors.toList()), securityGroupIds));
    }
    logger.info("Refreshed instance data in " + ((double)(System.currentTimeMillis() - startTime) / 1000) + " Seconds");

    return gatekeeperRDSInstances;
}
 
Example #16
Source File: RdsLookupService.java    From Gatekeeper with Apache License 2.0 5 votes vote down vote up
private String getApplicationTagforInstanceArn(AmazonRDSClient client, String arn){
    ListTagsForResourceRequest request = new ListTagsForResourceRequest();
    Optional<Tag> applicationTag = Optional.ofNullable(client.listTagsForResource(request.withResourceName(arn)).getTagList()
        .stream().filter(tag -> tag.getKey().equalsIgnoreCase(gatekeeperProperties.getAppIdentityTag()))
        .findFirst())
            .orElse(Optional.empty());

    return applicationTag.isPresent() ? applicationTag.get().getValue() : "NONE";
}
 
Example #17
Source File: AwsSessionService.java    From Gatekeeper with Apache License 2.0 4 votes vote down vote up
public AmazonRDSClient getRDSSession(AWSEnvironment environment){
    BasicSessionCredentials creds = credentialCache.getUnchecked(environment);
    AmazonRDSClient rds = awsSessionFactory.createRdsSession(creds);
    rds.setRegion(Region.getRegion(Regions.fromName(environment.getRegion())));
    return rds;
}
 
Example #18
Source File: AwsSessionFactory.java    From Gatekeeper with Apache License 2.0 4 votes vote down vote up
public AmazonRDSClient createRdsSession(BasicSessionCredentials basicSessionCredentials){
    return new AmazonRDSClient(basicSessionCredentials, clientConfiguration);
}
 
Example #19
Source File: RdsLookupService.java    From Gatekeeper with Apache License 2.0 4 votes vote down vote up
protected List<GatekeeperRDSInstance> loadInstancesAuroraGlobal(AWSEnvironment environment, Predicate<? super GlobalCluster> filter) {
    logger.info("Looking up Aurora Global Clusters");
    Long startTime = System.currentTimeMillis();
    DescribeDBClustersRequest describeDBClustersRequest = new DescribeDBClustersRequest();
    List<String> securityGroupIds = sgLookupService.fetchSgsForAccountRegion(environment);
    AmazonRDSClient amazonRDSClient = awsSessionService.getRDSSession(environment);

    List<GlobalCluster> auroraGlobalClusters = getGlobalClusters(amazonRDSClient).stream()
            .filter(filter)
            .collect(Collectors.toList());

    List<String> primaryDBClusterARNs = new ArrayList<>();
    Map<String, String> primaryToGlobalMapping = new HashMap<>();
    auroraGlobalClusters.forEach(globalCluster -> {
        globalCluster.getGlobalClusterMembers().forEach(
                memberCluster -> {
                    if(memberCluster.getIsWriter()) {
                        primaryDBClusterARNs.add(memberCluster.getDBClusterArn());
                        primaryToGlobalMapping.put(memberCluster.getDBClusterArn(), globalCluster.getGlobalClusterIdentifier());
                    }
                });
    });

    List<GatekeeperRDSInstance> gatekeeperRDSInstances = Collections.emptyList();

    // if there's no global clusters matched then don't make the call to look for primary clusters as the AWS API will fail. (AWS Internal Error)
    if(!primaryDBClusterARNs.isEmpty()) {
        DescribeDBClustersResult describeDBClustersResult = amazonRDSClient.describeDBClusters(
                describeDBClustersRequest.withFilters(new Filter()
                        .withName("db-cluster-id")
                        .withValues(primaryDBClusterARNs)));
        List<DBCluster> primaryClusters = new ArrayList<>(describeDBClustersResult.getDBClusters());

        while (describeDBClustersResult.getMarker() != null) {
            describeDBClustersResult = amazonRDSClient.describeDBClusters(new DescribeDBClustersRequest()
                    .withMarker(describeDBClustersResult.getMarker()));
            primaryClusters.addAll(describeDBClustersResult.getDBClusters());
        }

        // rename the cluster to the name of the global cluster
        primaryClusters.forEach(
                dbCluster -> dbCluster.setDBClusterIdentifier(primaryToGlobalMapping.get(dbCluster.getDBClusterArn()))
        );
        // process the primary aurora regional clusters, this re-uses the aurora processing with the global cluster as the cluster id instead of the primary cluster
        gatekeeperRDSInstances = loadToGatekeeperRDSInstanceAurora(environment, amazonRDSClient,
                primaryClusters, securityGroupIds, DatabaseType.AURORA_GLOBAL);

        logger.info("Refreshed instance data in " + ((double) (System.currentTimeMillis() - startTime) / 1000) + " Seconds");
    }

    return gatekeeperRDSInstances;
}
 
Example #20
Source File: RdsLookupService.java    From Gatekeeper with Apache License 2.0 4 votes vote down vote up
protected List<GatekeeperRDSInstance> loadInstancesAurora(AWSEnvironment environment, Predicate<? super DBCluster> filter) {
    logger.info("Looking up Aurora Clusters");
    Long startTime = System.currentTimeMillis();
    DescribeDBClustersRequest describeDBClustersRequest = new DescribeDBClustersRequest();
    List<String> securityGroupIds = sgLookupService.fetchSgsForAccountRegion(environment);
    AmazonRDSClient amazonRDSClient = awsSessionService.getRDSSession(environment);
    DescribeDBClustersResult result = amazonRDSClient.describeDBClusters(describeDBClustersRequest);

    // Aurora Global
    DescribeGlobalClustersResult describeGlobalClustersResult = amazonRDSClient.describeGlobalClusters(new DescribeGlobalClustersRequest());

    List<GlobalCluster> globalClusters = new ArrayList<>(describeGlobalClustersResult.getGlobalClusters());
    while(describeGlobalClustersResult.getMarker() != null){
        globalClusters.addAll(describeGlobalClustersResult.getGlobalClusters());
        amazonRDSClient.describeGlobalClusters(new DescribeGlobalClustersRequest()
                .withMarker(describeGlobalClustersResult.getMarker()));
    }

    Map<String, String> auroraClusterGlobalClusterMapping = new HashMap<>();

    globalClusters.forEach(globalCluster -> {
        globalCluster.getGlobalClusterMembers().forEach(member -> {
            auroraClusterGlobalClusterMapping.put(member.getDBClusterArn(), globalCluster.getGlobalClusterIdentifier());
        });
    });

    List<GatekeeperRDSInstance> gatekeeperRDSInstances = loadToGatekeeperRDSInstanceAurora(environment,amazonRDSClient,
            result.getDBClusters()
                    .stream()
                    .filter(cluster -> !auroraClusterGlobalClusterMapping.containsKey(cluster.getDBClusterArn()))
                    .filter(filter)
                    .collect(Collectors.toList()), securityGroupIds, DatabaseType.AURORA_REGIONAL);

    //At a certain point (Usually ~100 instances) amazon starts paging the rds results, so we need to get each page, which is keyed off by a marker.
    while(result.getMarker() != null) {
        result = amazonRDSClient.describeDBClusters(describeDBClustersRequest.withMarker(result.getMarker()));
        gatekeeperRDSInstances.addAll(loadToGatekeeperRDSInstanceAurora(environment, amazonRDSClient,
                result.getDBClusters()
                        .stream()
                        .filter(filter)
                        .collect(Collectors.toList()), securityGroupIds, DatabaseType.AURORA_REGIONAL));
    }
    logger.info("Refreshed instance data in " + ((double)(System.currentTimeMillis() - startTime) / 1000) + " Seconds");

    return gatekeeperRDSInstances;
}
 
Example #21
Source File: AWSDatabaseHolder.java    From billow with Apache License 2.0 4 votes vote down vote up
public AWSDatabaseHolder(Config config) {
    maxAgeInMs = config.getDuration("maxAge", TimeUnit.MILLISECONDS);

    final DefaultAWSCredentialsProviderChain awsCredentialsProviderChain = new DefaultAWSCredentialsProviderChain();

    final ClientConfiguration clientConfig = new ClientConfiguration();
    clientConfig.setRetryPolicy(new RetryPolicy(null, null, config.getInt("maxErrorRetry"), true));
    clientConfig.setSocketTimeout(config.getInt("socketTimeout") * 1000);

    final AmazonEC2 bootstrapEC2Client = AmazonEC2ClientBuilder.standard().withCredentials(awsCredentialsProviderChain).build();

    ec2Clients = Maps.newHashMap();
    rdsClients = Maps.newHashMap();
    sqsClients = Maps.newHashMap();
    dynamoDBClients = Maps.newHashMap();
    elasticacheClients = Maps.newHashMap();
    elasticsearchClients = Maps.newHashMap();

    final List<Region> ec2Regions = bootstrapEC2Client.describeRegions().getRegions();
    for (Region region : ec2Regions) {
        final String regionName = region.getRegionName();
        final String endpoint = region.getEndpoint();
        log.debug("Adding ec2 region {}", region);

        if (config.getBoolean("ec2Enabled")) {
            final AmazonEC2Client ec2Client = new AmazonEC2Client(awsCredentialsProviderChain, clientConfig);
            ec2Client.setEndpoint(endpoint);
            ec2Clients.put(regionName, ec2Client);
        }

        if (config.getBoolean("rdsEnabled")) {
            final AmazonRDSClient rdsClient = new AmazonRDSClient(awsCredentialsProviderChain, clientConfig);
            rdsClient.setEndpoint(endpoint.replaceFirst("ec2\\.", "rds."));
            rdsClients.put(regionName, rdsClient);
        }

        if (config.getBoolean("dynamodbEnabled")) {
            final AmazonDynamoDBClient dynamoDBClient =
                new AmazonDynamoDBClient(awsCredentialsProviderChain, clientConfig);
            dynamoDBClient.setEndpoint(endpoint.replaceFirst("ec2\\.", "dynamodb."));
            dynamoDBClients.put(regionName, dynamoDBClient);
        }

        if (config.getBoolean("sqsEnabled")) {
            final AmazonSQSClient sqsClient = new AmazonSQSClient(awsCredentialsProviderChain, clientConfig);
            sqsClient.setEndpoint(endpoint.replaceFirst("ec2\\.", "sqs."));
            sqsClients.put(regionName, sqsClient);
        }

        if (config.getBoolean("elasticacheEnabled")) {
            final AmazonElastiCacheClient elastiCacheClient = new AmazonElastiCacheClient
                (awsCredentialsProviderChain, clientConfig);
            elastiCacheClient.setEndpoint(endpoint.replaceFirst("ec2\\.", "elasticache."));
            elasticacheClients.put(regionName, elastiCacheClient);
        }

        if (config.getBoolean("elasticsearchEnabled")) {
            final AWSElasticsearchClient elasticsearchClient = new AWSElasticsearchClient
                (awsCredentialsProviderChain, clientConfig);
            elasticsearchClient.setEndpoint(endpoint.replaceFirst("ec2\\.", "es."));
            elasticsearchClients.put(regionName, elasticsearchClient);
        }
    }

    this.iamClient = AmazonIdentityManagementClientBuilder.standard()
        .withCredentials(awsCredentialsProviderChain)
        .withClientConfiguration(clientConfig)
        .build();

    if (config.hasPath("accountNumber")) {
        this.awsAccountNumber = config.getString("accountNumber");
    } else {
        this.awsAccountNumber = null;
    }

    if (config.hasPath("arnPartition")) {
        this.awsARNPartition = config.getString("arnPartition");
    } else {
        this.awsARNPartition = "aws";
    }

    rebuild();
}