Skip to content

Upgrade to AWS Java SDK v2 #6165

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 17 commits into
base: master
Choose a base branch
from
Draft

Upgrade to AWS Java SDK v2 #6165

wants to merge 17 commits into from

Conversation

jorgee
Copy link
Contributor

@jorgee jorgee commented Jun 5, 2025

This PR contains the changes to port the Amazon plugin to AWS SDK version 2. Find below the most relevant changes:

  • S3 Global Region flag: In v1, it was activated with S3Client.withForceGlobalBucketAcessEnabled(flag). In v2, it set the following flags S3Client.Builder.crossRegionAccessEnabled(flag) and S3Configuration.multiRegionAccessEnabled(flag).
  • Two S3Clients are created: the async client is used for operations performed through the S3TransferManager, and the sync client is used for other actions.

- AmazonS3Client.getS3AccountOwner() is not available in SDK v2. It was providing an ID used for checking the file access. In V2, the only way to retrieve the same ID is from a bucket owned by the user. To do it we need to list the buckets and get the owner field in the GetBucketACLResponse. If it is not possible to retrieve the ID because the user does not own any bucket, we perform the following fallback. In the case of READ access, it tries to retrieve the head of the object, It will fail if there isn't read access. In the case of writting, a warning is printed. It is the same as AWS NIO is doing to check the file access.

  • The setEndpoint and setRegion methods in the S3Client wrapper are removed as it is not available in the v2 clients. They were only used in tests.

  • CannedAccessControlList is split in two classes one for objects and another for buckets. In most of the code it has been substituted by ObjectCannedACL.

  • ContentType and ContentLength are part of the request instead of the ObjectMetadata, and they can be obtained invoking the S3client.headObject method in the SDK v2

  • S3ClientConfiguration doesn't exist in SDK v2. Two new classes have been created to emulate the same behaviour. They convert the properties to the SDK v2 sync and async client configurations.

  • SsoCredentialsProviderV1 class is not needed anymore as SDK v2 already manages the SSO credentials. The custom provider chain created in the S3FileSystemProvider.getCredetialsProvider0 to include the SsoCredentialsProviderV1 ihas been replace by the DefaultCredentialProvider in v2.

  • Credentials and config are automatically merged by SDK v2. No option for NXF_DISABLE_AWS_CONFIG_MERGE.

  • In V2, clients and requests are immutable and must be generated with a builder class. Some helper methods have been modified to pass builder classes instead of requests, such as makeJobDefRequest, configJobRefRequest, addVolumeMountsToContainer, etc.

  • S3 Parallel Download was deprecated and S3CopyStream was not used. They have been removed.

  • In v1, the upload directory was performed by walking through the different directory files and uploading them one by one. In v2, it has been substituted by the uploadDirectory method in the SDK.

jorgee added 5 commits June 5, 2025 12:38
Signed-off-by: jorgee <[email protected]>
Signed-off-by: jorgee <[email protected]>
Signed-off-by: jorgee <[email protected]>
Signed-off-by: jorgee <[email protected]>
Copy link

netlify bot commented Jun 5, 2025

Deploy Preview for nextflow-docs-staging ready!

Name Link
🔨 Latest commit 951f23e
🔍 Latest deploy log https://app.netlify.com/projects/nextflow-docs-staging/deploys/6852cd4b70372b0008b2bfe5
😎 Deploy Preview https://deploy-preview-6165--nextflow-docs-staging.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@bentsherman bentsherman mentioned this pull request Jun 16, 2025
@bentsherman bentsherman changed the title AWS SDK V2 Porting (without AWS NIO SPI) Upgrade to AWS Java SDK v2 Jun 16, 2025
@jorgee jorgee marked this pull request as ready for review June 17, 2025 16:21
@jorgee jorgee requested review from a team as code owners June 17, 2025 16:21
@jorgee
Copy link
Contributor Author

jorgee commented Jun 17, 2025

It is ready for review

@jorgee jorgee requested review from pditommaso and bentsherman June 18, 2025 07:35
Copy link
Member

@pditommaso pditommaso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks awesome. Made a few minor comments

Comment on lines 428 to 437
CompletedMultipartUpload completedUpload = CompletedMultipartUpload.builder()
.parts(completedParts)
.build();

CompleteMultipartUploadRequest completeRequest = CompleteMultipartUploadRequest.builder()
.bucket(targetBucketName)
.key(targetObjectKey)
.uploadId(uploadId)
.multipartUpload(completedUpload)
.build();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some indentation can make it better readable

try{
downloadFile.completionFuture().get();
} catch (InterruptedException e){
log.debug("S3 download file: s3://{}/{} cancelled", source.getBucket(), source.getKey());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
log.debug("S3 download file: s3://{}/{} cancelled", source.getBucket(), source.getKey());
log.debug("S3 download file: s3://{}/{} interrupted", source.getBucket(), source.getKey());

Comment on lines 510 to 511
log.debug("S3 download file: s3://{}/{} exception thrown", source.getBucket(), source.getKey());
throw new IOException(e.getCause());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
log.debug("S3 download file: s3://{}/{} exception thrown", source.getBucket(), source.getKey());
throw new IOException(e.getCause());
String msg = String.format("Exception thrown with downloading S3 object s3://{}/{}", source.getBucket(), source.getKey());
throw new IOException(msg, e);

Logging the error and re-throwing will result in double logging it, which can be confusing.

Alternatively it could be done just

throw e.getCause()

Thread.currentThread().interrupt();
}
} catch (ExecutionException e) {
log.debug("S3 deownload directory: s3://{}/{} exception thrown", source.getBucket(), source.getKey());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as above

Thread.currentThread().interrupt();
} catch (ExecutionException e) {
log.debug("S3 upload file: s3://{}/{} exception thrown", target.getBucket(), target.getKey());
throw new IOException(e.getCause());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as above

return getObjectMetadata(bucketName,key).getSSEAwsKmsKeyId();
} catch (ExecutionException e) {
log.debug("S3 upload directory: s3://{}/{} exception thrown", target.getBucket(), target.getKey());
throw new IOException(e.getCause());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as above

@jorgee jorgee marked this pull request as draft June 18, 2025 14:02
@jorgee jorgee marked this pull request as draft June 18, 2025 14:02
@jorgee jorgee marked this pull request as draft June 18, 2025 14:02
@jorgee
Copy link
Contributor Author

jorgee commented Jun 18, 2025

I have found an issue with multi-part uploads when uploading large files. I move to draft until I fix it.

Signed-off-by: Ben Sherman <[email protected]>
Signed-off-by: Ben Sherman <[email protected]>
@jorgee
Copy link
Contributor Author

jorgee commented Jun 19, 2025

In one of the changes that I did to support the Signer override and UserAgent is breaking the multipart upload. I changed the way about how the transfer manager's S3AsyncClient is created and the multipart upload with large files is having issues. It is creating too many parts and it can exhaust the heap memory or a time out when acquaring the connections. It is not happening if we use the default S3CrtAsyncClient but it does not allow to define the UserAgent and Signer as a clientoverride. I am still looking for a way to define them but I am wondering how relevant are these options. Is there a possibility to deprecate them?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants