Java – Get file in a AWS S3 Bucket

In this post we will provide an example of how to get a file in a AWS S3 bucket using Java.


You will need to add the following amazon-sdk dependancy to your project

You will also need to setup your AWS credentials a simple approach is to export the following environment variables:

  • AWS_REGION=<your-aws-region>
  • AWS_ACCESS_KEY_ID=<your-access-key>
  • AWS_SECRET_ACCESS_KEY=<your-secret-access-key>

For alternative approaches please check reference 1 below for more details.

Get file in a AWS S3 bucket:

The example below assumes you have a bucket already created with files on S3.

Running the above code will download a copy the content from the file on s3 into the new ‘downloaded-file.jpg’ file. Note you will need to have access to download files from the bucket. For more information relating to AWS access controls please refer to the AWS documentation

In conclusion I hope you found this post useful and it helps you understand how to get files within an S3 bucket.

Similar posts:

  1. Java 8 streams map example
  2. Java 8 Streams flatmap example
  3. Java List files in a directory
  4. List files in a AWS S3 bucket


  1. AWS credentials setup
  2. What is Amazon S3
  3. AWS S3 access control

Leave a Reply