diff --git a/render-app/src/main/java/org/janelia/alignment/loader/S3Handler.java b/render-app/src/main/java/org/janelia/alignment/loader/S3Handler.java index 139060dd2..1b91a4904 100644 --- a/render-app/src/main/java/org/janelia/alignment/loader/S3Handler.java +++ b/render-app/src/main/java/org/janelia/alignment/loader/S3Handler.java @@ -57,9 +57,32 @@ public static S3Handler getSharedInstance() private static synchronized void buildInstance() throws IOException { if (SHARED_INSTANCE == null) { try { - final AWSCredentialsProvider credentialsProvider = new DefaultAWSCredentialsProviderChain(); - final AmazonS3 s3Client = AmazonS3ClientBuilder.standard().withCredentials(credentialsProvider).build(); - SHARED_INSTANCE = new S3Handler(s3Client); + final AmazonS3ClientBuilder clientBuilder = AmazonS3ClientBuilder.standard(); + + if (this.s3Parameters.containsKey("aws_secret_access_key") && this.s3Parameters.containsKey("aws_access_key_id")){ + final AWSCredentials credentials = new BasicAWSCredentials(this.s3Parameters.get("aws_access_key_id"), this.s3Parameters.get("aws_secret_access_key")); + final AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(credentials); + clientBuilder.setCredentials(credentialsProvider); + } else if (this.s3Parameters.containsKey("profile_name")) { + final AWSCredentialsProvider credentialsProvider = new ProfileCredentialsProvider(this.s3Parameters.get("profile_name")); + clientBuilder.setCredentials(credentialsProvider); + } else { + final AWSCredentialsProvider credentialsProvider = new DefaultAWSCredentialsProviderChain(); + clientBuilder.setCredentials(credentialsProvider); + } + + String region = (String) this.s3Parameters.getOrDefault("region_name", clientBuilder.getRegion()); + if (this.s3Parameters.containsKey("endpoint_url")) { + final EndpointConfiguration endpointConfig = new EndpointConfiguration(this.s3Parameters.get("endpoint_url"), region); + final AmazonS3 s3Client = clientBuilder.withEndpointConfiguration(endpointConfig).build(); + SHARED_INSTANCE = new S3Handler(s3Client); + } else { + final AmazonS3 s3Client = clientBuilder.withRegion(region).build(); + SHARED_INSTANCE = new S3Handler(s3Client); + } + //final AWSCredentialsProvider credentialsProvider = new DefaultAWSCredentialsProviderChain(); + //final AmazonS3 s3Client = AmazonS3ClientBuilder.standard().withCredentials(credentialsProvider).build(); + //SHARED_INSTANCE = new S3Handler(s3Client); } catch (final AmazonServiceException ase) { throw new IOException("Amazon S3 service failure for error type " + ase.getErrorType(), ase); } catch (final AmazonClientException ace) {