aws-sdk-java-v2 icon indicating copy to clipboard operation
aws-sdk-java-v2 copied to clipboard

S3AsyncClient getObject write file directly to disk

Open earlybard opened this issue 2 years ago • 3 comments

Describe the feature

Allow S3AsyncClient.getObject to write downloaded objects directly to disk, rather than buffering in ByteBuffers via an AsyncResponseTransformer.

aws-crt-java recently added support for this under the hood: https://github.com/awslabs/aws-crt-java/pull/825

Use Case

When dealing with large objects (10GB+) and high speeds (10Gb/s), the Java heap is quickly exhausted when downloading files via GetObject, even if their destination is on disk via e.g. client.getObject(req, AsyncResponseTransformer.toFile(file))

This causes gigabytes of unnecessary allocations and GCs, to the point of the AWS Java SDK not being feasible for my application that deals with large files.

My current solution is to call a standalone native binary to perform this download to disk, which adds plenty of extra complexity and loses the many benefits of using your SDK.


Another advantage was stated in the crt-java repo: https://github.com/awslabs/aws-crt-java/pull/825#issuecomment-2405557508

It would lower latency, by removing an additional copy from C -> Java, and improve memory usage (no need to allocate a ByteBuffer to hold the additional copy).

Proposed Solution

No preference how this is implemented, either a standalone S3AsyncClient::getObjectToFile interface method, or an option on GetObjectRequest.

Other Information

I don't have any issue when calling PutObject for very large files from disk. The JVM heap usage stay very low.

Acknowledgements

  • [ ] I may be able to implement this feature request
  • [ ] This feature might incur a breaking change

AWS Java SDK version used

2.28.20

JDK version used

21

Operating System and version

Ubuntu 24.04

earlybard avatar Oct 11 '24 03:10 earlybard

@earlybard feature request acknowledged, we'll work on the integration with aws-crt-java.

debora-ito avatar Oct 11 '24 18:10 debora-ito

Implemented via https://github.com/aws/aws-sdk-java-v2/pull/6289 and released in version 2.32.11.

debora-ito avatar Nov 14 '25 22:11 debora-ito

This issue is now closed. Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one.

github-actions[bot] avatar Nov 14 '25 22:11 github-actions[bot]