Skip to content

Commit

Permalink
fix: init CRT early so it is done before any task runs
Browse files Browse the repository at this point in the history
  • Loading branch information
loicmathieu committed Aug 29, 2024
1 parent b832620 commit 4955da3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/java/io/kestra/plugin/aws/s3/AbstractS3Object.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@ public abstract class AbstractS3Object extends AbstractConnection implements Abs
protected String requestPayer;

protected String bucket;

static {
// Initializing CRT will download the S3 native library into /tmp.
// With Java Security enabled, we need to do it early so it is done out of a task execution.
S3Service.initCrt();
}
}
7 changes: 7 additions & 0 deletions src/main/java/io/kestra/plugin/aws/s3/S3Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import software.amazon.awssdk.crt.CRT;
import software.amazon.awssdk.services.s3.S3AsyncClient;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.GetObjectRequest;
Expand All @@ -27,6 +28,12 @@
import java.util.stream.Collectors;

public class S3Service {

public static void initCrt() {
// This will init CRT and loads the native library
CRT.getArchIdentifier();
}

public static Pair<GetObjectResponse, URI> download(RunContext runContext, S3AsyncClient client, GetObjectRequest request) throws IOException, ExecutionException, InterruptedException {
// s3 require non existing files
File tempFile = runContext.workingDir().createTempFile(FileUtils.getExtension(request.key())).toFile();
Expand Down

0 comments on commit 4955da3

Please sign in to comment.