class AwsDataSourceServiceImpl implements AwsDataSourceService {

    public List<AwsDBInstanceDTO> getAwsDBInstances(AWSCredentials awsCredentials, String amazonDBService,
            String region) {
        try {
//            if region is presended as endpoint - strip domain name
            if (region!=null && region.contains(".")) {
                region=region.split("\\.")[0];
            }
            if (amazonDBService.toLowerCase().equals(RDS)) {
                //Make RDS service calls to read all available RDS instances
                AmazonRDS rdsClient = AmazonRDSClientBuilder.
                        standard().
                        withCredentials(new AWSStaticCredentialsProvider(awsCredentials)).
                        withRegion(region).
                        build();
//                AmazonRDSClient rdsClient = new AmazonRDSClient(awsCredentials);
//                if (region != null) {
//                    rdsClient.setEndpoint(RDS + "." + region);
//                }
                return toRDSInstancesDTOs(getRdsInstances(rdsClient), amazonDBService);
            } else if (amazonDBService.toLowerCase().equals(Redshift)) {
                //Make RedShift service calls to read all available RedShift instances
                AmazonRedshift redshiftClient = AmazonRedshiftClientBuilder.
                        standard().
                        withRegion(region).
                        withCredentials(new AWSStaticCredentialsProvider(awsCredentials)).
                        build();
//                if (region != null) {
//                    redshiftClient.setEndpoint(Redshift + "." + region);
//                }
                return toRedshiftInstancesDTOs(getRedshiftInstances(redshiftClient), amazonDBService);
            } else {
                return new ArrayList<AwsDBInstanceDTO>();
            }
        } catch (AmazonServiceException ex) {
            log.warn("Loading AWS data source metadata for " + amazonDBService +": " + ex.getMessage());

            String errorCode = ex.getErrorCode();
            if (ex.getStatusCode() == 403 && errorCode != null) {
                errorCode = errorCode.toLowerCase();
                if (errorCode.equals(ACCESS_DENIED)) {
                    return generateDBServiceInfoStatus(amazonDBService, "resource.dataSource.aws.access.denied");
                } else if (errorCode.equals(INVALID_CLIENT_TOKEN_ID)) {
                    throw new JSShowOnlyErrorMessage(messageSource.getMessage("" +
                            "aws.exception.datasource.accessKey.invalid", null, LocaleContextHolder.getLocale()));
                } else if (errorCode.equals(SIGNATURE_DOES_NOT_MATCH)) {
                    throw new JSShowOnlyErrorMessage(messageSource.getMessage("" +
                            "aws.exception.datasource.secretKey.invalid", null, LocaleContextHolder.getLocale()));
                }
            }

            return generateDBServiceInfoStatus(amazonDBService, "[" + ex.getMessage() + "]");
        } catch (AmazonClientException ex) {
            if (ex.getCause() instanceof UnknownHostException) {
                return generateDBServiceInfoStatus(region, "resource.dataSource.aws.unknown.host");
            }

            return generateDBServiceInfoStatus(amazonDBService, "[" + ex.getMessage() + "]");
        }
    }

}