diff --git a/zulia-server/src/main/java/io/zulia/server/filestorage/S3DocumentStorage.java b/zulia-server/src/main/java/io/zulia/server/filestorage/S3DocumentStorage.java index 657bcd72..61c051f9 100644 --- a/zulia-server/src/main/java/io/zulia/server/filestorage/S3DocumentStorage.java +++ b/zulia-server/src/main/java/io/zulia/server/filestorage/S3DocumentStorage.java @@ -17,6 +17,7 @@ import org.bson.Document; import org.xerial.snappy.SnappyInputStream; import org.xerial.snappy.SnappyOutputStream; +import software.amazon.awssdk.auth.credentials.*; import software.amazon.awssdk.core.ResponseInputStream; import software.amazon.awssdk.core.sync.RequestBody; import software.amazon.awssdk.regions.Region; @@ -68,7 +69,17 @@ public S3DocumentStorage(MongoClient mongoClient, String indexName, String dbNam this.indexName = indexName; this.dbName = dbName; this.sharded = sharded; - this.s3 = S3Client.builder().region(Region.of(this.region)).build(); + AwsCredentialsProviderChain credentialsProvider = AwsCredentialsProviderChain.builder() + .credentialsProviders( + InstanceProfileCredentialsProvider.builder().build(), + ContainerCredentialsProvider.builder().build(), + EnvironmentVariableCredentialsProvider.create(), + SystemPropertyCredentialsProvider.create(), + ProfileCredentialsProvider.builder().build() + ) + .build(); + + this.s3 = S3Client.builder().region(Region.of(this.region)).credentialsProvider(credentialsProvider).build(); ForkJoinPool.commonPool().execute(() -> { MongoDatabase db = client.getDatabase(dbName); @@ -107,7 +118,7 @@ public void storeAssociatedDocument(AssociatedDocument doc) throws Exception { PutObjectRequest req = PutObjectRequest.builder().bucket(bucket).key(key).contentLength((long) bytes.length).build(); - ByteArrayOutputStream baos = new ByteArrayOutputStream(bytes.length); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); SnappyOutputStream os = new SnappyOutputStream(baos); os.write(bytes); os.flush(); @@ -154,8 +165,7 @@ public void getAssociatedDocuments(Writer outputstream, Document filter) throws for (Document doc : found) { if (first) { first = false; - } - else { + } else { outputstream.write(",\n"); } @@ -334,7 +344,7 @@ private AssociatedDocument parseTOC(Document doc) throws IOException { GetObjectRequest gor = GetObjectRequest.builder() .bucket(s3Info.getString("bucket")) .key(s3Info.getString("key")) - .build() ; + .build(); ResponseInputStream results = s3.getObject(gor); InputStream compression = new SnappyInputStream(results); try (compression) {