Read on Medium: One-stop guide: Kotlin + Spring Boot 2 + AWS S3 + Testcontainers
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.
- 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
Being accelerator for learning and diving into the best cutting edge tools listed above by demonstrating how they can work together.
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 |
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
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
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
If you need any kind of support don't hesitate to let me know 😉
Created by Alex Antukhov