This repository is a small reference project for uploading to and downloading from Amazon S3 with Java.
It is not a production-ready library. It is a compact set of S3 examples you can read, run, and adapt.
S3TextUpload: upload a small text object to S3S3FileUpload: upload a local file with S3 multipart upload behaviorS3ObjectDownload: download an object and demonstrate a few retrieval options
All samples use the AWS SDK for Java v2 and follow the same runtime configuration pattern.
Requirements:
- Java 8 or later
- Maven 3.6 or later
- an AWS account with S3 access
- AWS credentials available locally
A typical local setup is:
aws configureFor a quick local starting point, see .env.example. The repository does not load .env files automatically, but the file shows the variables you may want to export before running the samples.
The fastest way to try the repository end to end is:
make roundtrip-object BUCKET=my-s3-sample-bucket KEY=hello.txt CONTENT="hello from make"If the bucket does not exist yet:
make roundtrip-object BUCKET=my-s3-sample-bucket KEY=hello.txt CONTENT="hello from make" CREATE_BUCKET=trueThat flow uploads a text object and then downloads the same object immediately after.
Makefile
LICENSE
README.md
.env.example
.github/
workflows/
ci.yml
scripts/
upload-text.sh
upload-file.sh
download-object.sh
roundtrip-object.sh
src/
main/java/net/jrodolfo/awss3/
SampleInput.java
upload/
S3TextUpload.java
S3FileUpload.java
download/
S3ObjectDownload.java
test/java/net/jrodolfo/awss3/
SampleInputTest.java
integration/
S3IntegrationTest.java
upload/
S3TextUploadConfigTest.java
S3FileUploadConfigTest.java
download/
S3ObjectDownloadConfigTest.java
The most useful entry point is make:
make help
make test
make upload-text BUCKET=my-bucket KEY=hello.txt CONTENT="hello from make"
make upload-file BUCKET=my-bucket FILE=/path/to/file.zip
make download-object BUCKET=my-bucket KEY=hello.txt
make roundtrip-object BUCKET=my-bucket KEY=hello.txt CONTENT="hello from make"
make test-integration INTEGRATION_BUCKET=my-s3-sample-bucketThe repository also includes direct shell wrappers:
scripts/upload-text.shscripts/upload-file.shscripts/download-object.shscripts/roundtrip-object.sh
Each script supports --help.
Each sample follows the same rule:
- positional command-line arguments take priority
- otherwise the sample checks environment variables
- if a required value is still missing, the sample exits with a clear error
Common environment variables:
AWS_S3_BUCKETAWS_S3_KEYAWS_S3_REGIONAWS_S3_FILEAWS_S3_CONTENTAWS_S3_CREATE_BUCKETAWS_S3_CLEANUPAWS_S3_MULTIPART_THRESHOLDAWS_PROFILE
Use these if you want to run the Java classes directly with Maven instead of make or the shell scripts.
Arguments:
bucketkeycontentoptional, defaultTesting with the {sdk-java}regionoptional, defaultus-east-2createBucketoptional, defaultfalsecleanupoptional, defaultfalse
Example:
mvn -q exec:java \
-Dexec.mainClass=net.jrodolfo.awss3.upload.S3TextUpload \
-Dexec.args="my-s3-sample-bucket hello.txt 'hello from java' us-east-2 false false"Arguments:
bucketfilePathkeyoptional, default local file nameregionoptional, defaultus-east-2multipartThresholdBytesoptional, default5242880
Example:
mvn -q exec:java \
-Dexec.mainClass=net.jrodolfo.awss3.upload.S3FileUpload \
-Dexec.args="my-s3-sample-bucket /path/to/file.zip file.zip us-east-2 5242880"Arguments:
bucketkeyregionoptional, defaultus-east-2profileoptional
Example:
mvn -q exec:java \
-Dexec.mainClass=net.jrodolfo.awss3.download.S3ObjectDownload \
-Dexec.args="my-s3-sample-bucket hello.txt us-east-2 default"The repository includes an opt-in integration test that performs a real S3 round trip:
- upload and download a temporary text object
- upload and download a temporary local file
- verify the downloaded content matches
- delete the temporary objects
Normal mvn test runs stay lightweight. The integration test is skipped unless AWS_S3_INTEGRATION_BUCKET is set.
Run it directly:
AWS_S3_INTEGRATION_BUCKET=my-s3-sample-bucket \
mvn -Dtest=net.jrodolfo.awss3.integration.S3IntegrationTest testOr through make:
make test-integration INTEGRATION_BUCKET=my-s3-sample-bucketOptional integration variables:
AWS_S3_INTEGRATION_REGION, defaultus-east-2AWS_S3_INTEGRATION_PROFILE, optional named AWS profile
Local build:
mvn testThe test suite covers runtime input parsing and sample configuration behavior. It does not run real S3 operations unless you explicitly enable the integration test.
GitHub Actions runs mvn test automatically on pushes to main and on pull requests. The workflow file lives at .github/workflows/ci.yml.
Error: Unable to reach AWS S3...Check your AWS credentials, active profile, network access, and region.Error: S3 request failed...Confirm the bucket, object key, region, and IAM permissions for the operation.Error: Object not found in S3...Double-check the bucket, key, and region used by the download command.Error: Unable to read the local file...Confirm the local file path exists and is readable before usingS3FileUpload.Required command not found: mvnInstall Maven and ensuremvnis available on yourPATH.
- AWS SDK for Java 2.x developer guide
- Amazon S3 object download examples
- Multipart uploads in Amazon S3 with Java
- Software Developer: Rod Oliveira
- GitHub: https://github.com/jrodolfo
- Webpage: https://jrodolfo.net
- MIT License
- Copyright (c) 2026 Rod Oliveira
- See LICENSE