Amazon S3 – Upload/Download files with SpringBoot Amazon S3 application.

Amazon S3 – Upload_Download files with SpringBoot Amazon S3 application.

Amazon Simple Storage Service (Amazon S3) is object storage built to store and retrieve any amount of data from web or mobile. Amazon S3 is designed to scale computing easier for developers. For starting, in the tutorial, JavaSampleApproach show you how to create a SpringBoot Amazon S3 application.

Related post:
Amazon S3 – How to upload/download large files to S3 with SpringBoot Amazon S3 MultipartFile application

I. Technologies

– Java 8
– Maven 3.6.1
– Spring Tool Suite: Version 3.8.4.RELEASE
– Spring Boot: 1.5.4.RELEASE
– Amazon S3

II. SpringBoot Amazon S3

In the tutorial, JavaSampleApproach will setup an Amazon S3 bucket, then use SpringBoot application with aws-java-sdk to upload/download files to/from S3.

amazon s3 starter - architecture

– For init an AmazonS3 client, we use:

– For upload S3 objects, we use:

– For download S3 objects, we use:

III. Practice

In the tutorial, we will setup an Amazon S3 bucket, an IAM user and create a SpringBoot application to upload/download files to/from S3.

SpringBoot Amazon S3 starter - project structure

Step to do:
Setup Amazon S3
– Sign Up
– Create a Bucket
– Create an IAM user

SpringBoot Amazon S3 application
– Create SpringBoot project
– Set Amazon S3 client
– Implement S3 download/upload services
– Implement simple client
– Run and check results

1. Setup Amazon S3

1.1 Sign Up

Go to

springboot amazon s3 starter - sign up

Choose Get started with Amazon S3.

Follow the instructions on the screen for sign up.
-> AWS will notify you by email when your account is active and available for you to use.

1.2 Create a Bucket

Now, your account is ready to use with AWS.
-> Sign in to AWS:

Choose Create bucket, input information for creating bucket:

springboot amazon s3 starter - input info for create buckett

Press Create -> result:

springboot amazon s3 starter - input info for create bucket - result

1.3 Create an IAM user

Go to
In the navigation pane, choose Users and then choose Add user.

springboot amazon s3 starter - choose user

Input User name, choose Programmatic access for Access type:

amazon s3 starter - add user info

Press Next: Permissions button -> go to Set permissions for jsa-user screen.
Now, choose Attach existing policies directly -> filter policy type s3, then check AmazonS3FullAccess:

amazon s3 starter - add policies

Press Next: Review:

amazon s3 starter - review policies

Press Create user:

Press Download .csv for {Access key ID, Secret access key}.

2. SpringBoot Amazon S3 application

2.1 Create SpringBoot project

Using SpringToolSuite to create a SpringBoot project. Then add needed dependency aws-java-sdk:

2.2 Set Amazon S3 client

Create a file for setup AmazonS3 client:

Open, add aws configuration:

Note: Keep private for secret_access_key.

2.3 Implement S3 download/upload services

Create S3Services interface:

Implement S3Services interface with S3ServicesImpl:

For support displayText, we create an Utility class with a function Utility.displayText(InputStream input):

2.4 Implement simple client

Using S3Services, We implement a client for upload/download files:

2.5 Run and check results

– Create a file C:\\s3\\jsa-s3-upload-file.txt with content:

– Build and Run the SpringBoot project with commandlines {mvn clean install, mvn spring-boot:run}.

-> Upload file:

amazon s3 starter - upload results

-> Download file, Logs:

IV. Sourcecode


By grokonez | July 20, 2017.

Last updated on April 21, 2019.

Related Posts

2 thoughts on “Amazon S3 – Upload/Download files with SpringBoot Amazon S3 application.”

Got Something To Say:

Your email address will not be published. Required fields are marked *