Upload files to your amazon s3 bucket using Spring Boot Web.
✨ Getting Started | 🚀 Download |
---|
Follow the below instructions to get started with the source code:
- Make sure you have all Requirements
- Download Source Code
- Configure storage properties
- Open Project in your favourite Java IDE and Enjoy!
Make sure you have the below requirements before starting:
- OpenJDK 11 (LTS)
- IntelliJ IDEA
- Basic Knowledge about Spring and Java
- AWS Account
- IAM user with access-key and secret-access-key (user’s credentials)
- Amazon S3 bucket
You can get access to the source code by using one of the following ways:
- ✨ Download Source Code
- 🔥 Clone the repository locally:
git clone https://github.com/germanfica/tut-aws-amazon-s3-spring-boot.git
- AWS Java SDK Amazon S3:
<dependencies>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>s3</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>bom</artifactId>
<version>2.17.124</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
- Project Lombok:
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
</dependency>
Open src/main/resources/config/storage.properties
amazon.s3.bucket-name = your-bucket-name
amazon.s3.region = ${AWS_DEFAULT_REGION}
amazon.aws.credentials.access-key = ${AWS_ACCESS_KEY_ID}
amazon.aws.credentials.secret-access-key = ${AWS_SECRET_ACCESS_KEY}
For more security, create environment variables in your machine, AWS_ACCESS_KEY_ID
, AWS_SECRET_ACCESS_KEY
, AWS_DEFAULT_REGION
and populate it with IAM informations.
Linux or macOS
export AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE
export AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
export AWS_DEFAULT_REGION=us-west-2
Windows Command Prompt
setx AWS_ACCESS_KEY_ID AKIAIOSFODNN7EXAMPLE
setx AWS_SECRET_ACCESS_KEY wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
setx AWS_DEFAULT_REGION us-west-2
PowerShell
$Env:AWS_ACCESS_KEY_ID="AKIAIOSFODNN7EXAMPLE"
$Env:AWS_SECRET_ACCESS_KEY="wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
$Env:AWS_DEFAULT_REGION="us-west-2"
Open src/main/resources/application.properties
spring.servlet.multipart.max-file-size=10MB
spring.servlet.multipart.max-request-size=10MB
mvn spring-boot:run
If you want you can test your API using postman. I share my postman collection with you so you can fork it with the following link:
None.