One-stop guide: Kotlin + Spring Boot 2 + AWS S3 + Testcontainers
Read on Medium: One-stop guide: Kotlin + Spring Boot 2 + AWS S3 + Testcontainers
💡 Idea
Application implements the sample of CRUD REST API for AWS S3 (Simple Storage Service) to list, upload and download objects of buckets. Service covered by an integration test which starts AWS S3 mock inside Docker container using Localstack.
⚙️ Components
- Core:
- Kotlin 1.4, JDK 11
- Spring Boot 2.4
- Gradle and OCI - Docker image assembling
- AWS SDK for Java 2.0 with S3 integration test starter
- Testing:
- JUnit 5
- Testcontainers - library to use Docker in tests
- Localstack - mocking framework to test AWS cloud services
- Utils:
- Swagger 2
- Spring Actuator
💼 Goal
Being accelerator for learning and diving into the best cutting edge tools listed above by demonstrating how they can work together.
Deployment
Environment variables
Variable | Description | Default value |
---|---|---|
AWS | ||
AWS_REGION | Listening port of embedded Tomcat | us-east-1 |
AWS_ACCESS_KEY | Access key for an AWS IAM user | |
AWS_SECRET_KEY | Secret key for the Access Key | |
WEB-SERVER | ||
SERVER_PORT | Listening port of embedded Tomcat | 8080 |
MAX_FILE_SIZE | Maximum size of each uploading file of request | 10MB |
MAX_REQUEST_SIZE | Maximum size of request | 10MB |
DEBUG | ||
SWAGGER_ENABLED | Switch on the JSON and GUI documentation for the REST API | false |
LOG_FILE | Set the relative or absolute path to the log file | s3warehouse.log |
ACTUATOR_LOG_FILE | Provides an access to log file through the /status/logfile | false |
Main commands
Action | CLI command |
---|---|
Run app | ./gradlew bootRun --args='--AWS_ACCESS_KEY=VALUE --AWS_SECRET_KEY=VALUE' * |
Run tests | ./gradlew test |
Build Docker image | ./gradlew bootBuildImage |
Run container | docker run -dit -e AWS_ACCESS_KEY=VALUE -e AWS_SECRET_KEY=VALUE -p 8080:8080 antukhov/s3warehouse:0.1 * |
[ * ] - don't forget to change values of environment variables
Quick start with the ready-to-use Docker
docker run -dit \
-e AWS_REGION=REGION_VALUE \
-e AWS_ACCESS_KEY=KEY_VALUE \
-e AWS_SECRET_KEY=SECRET_KEY \
-e SWAGGER_ENABLED=true \
-p 8085:8080 \
docker.pkg.github.com/antukhov/s3warehouse/s3warehouse:0.1
REST API documentation
Format | URL |
---|---|
HTML | http://localhost:8080/swagger-ui/index.html * |
JSON | http://localhost:8080/v2/api-docs * |
[ * ] - don't forget to change hostname and port if needed
Support
If you need any kind of support don't hesitate to let me know
Created by Alex Antukhov