In this project, we will use LocalStack to locally simulate some services provided by AWS Cloud such as OpenSearch, S3, and Secrets Manager. Additionally, to simplify the use of AWS managed services, we will use Spring Cloud AWS.
Note: Check out the
springboot-aws-localstack-dynamodb-lambda-sns-sqsrepository. In it, we have developed two Spring Boot applications for producing and listening to news updates. We also utilized LocalStack to locally simulate AWS Cloud services such asDynamoDB,Lambda,SNSandSQS.
On ivangfr.github.io, I have compiled my Proof-of-Concepts (PoCs) and articles. You can easily search for the technology you are interested in by using the filter. Who knows, perhaps I have already implemented a PoC or written an article about what you are looking for.
- [Medium] Spring Boot Apps for Movie Indexing/Search with AWS OpenSearch, S3 and Secrets Manager
- [Medium] Spring Boot apps to trigger and consume DynamoDB News table updates using AWS Lambda, SNS and SQS
- [Medium] Implementing a Spring Boot App using AWS DynamoDB as database
- [Medium] Implementing a Spring Boot App that uses AWS Secrets Manager to store its MongoDB credentials
- [Medium] Implementing a Serverless AWS Lambda with Spring Cloud Function & AWS Adapter
- [Medium] Using AWS SNS and SQS to stream Alerts from a Spring Boot producer to consumers
- 
Spring BootJava Web application that exposes a REST API and provides a UI for indexing movies.It has the following endpoints: GET /api/movies/{imdb} POST /api/movies {"imdb":"...", "title":"...", "posterUrl":"...", "year":"...", "released":"...", "imdbRating":"...", "genre":"...", "runtime":"...", "director":"...", "writer":"...", "actors":"...", "plot":"...", "language":"...", "country":"...", "awards":"..."} POST /api/movies/{imdb}/uploadPosterThe information of the movies, such as imdb,title,year, etc, are stored inOpenSearchthat is hosted inLocalStack. The movie'sposteris stored inS3buckets.The movie-apihas access toOMDb APIto search and add easily new movies. To make requests toOMDb API, anapiKeyis needed. This key is stored as a secret inSecrets Manager.
- 
Spring BootJava Web application with a user interface designed for searching movies indexed inmovie-api. To populate its UI with movie data,movie-uicommunicates withmovie-apiby making requests to its endpoints. The movie’s poster is retrieved from theS3bucket.
- 
Java 21or higher;
- 
OMDb APIKEYTo search for movies in OMDb API, we need to obtain an API KEY fromOMDb API. To do it, access https://www.omdbapi.com/apikey.aspx and follow the steps provided by the website.
- 
In a terminal, make sure you are inside the springboot-aws-localstack-opensearch-s3-secretsmanagerroot folder;
- 
Start LocalStackDocker container:DEBUG=1 docker compose up -d 
- 
[Optional] Debug logs are enabled to provide more insights into what is happening. To monitor localstackDocker container logs, run the command below:docker logs localstack 
- 
Initialize LocalStackby running the following script:./init-localstack.sh <OMDB_API_KEY> The script requires OMDB_API_KEYas first and unique argument. The script will create:- a domain for OpenSearchas well as themoviesindex using themovies-settings.jsonprovided;
- bucket com.ivanfranchin.movieapi.postersinS3;
- a secret for OMDB_API_KEYinSecrets Manager.
 
- a domain for 
- 
movie-api In a terminal, inside the springboot-aws-localstack-opensearch-s3-secretsmanagerroot folder, run the following command:export AWS_REGION=eu-west-1 && export AWS_ACCESS_KEY_ID=key && export AWS_SECRET_ACCESS_KEY=secret && \ ./mvnw clean spring-boot:run --projects movie-api 
- 
movie-ui In another terminal and, inside the springboot-aws-localstack-opensearch-s3-secretsmanagerroot folder, run the command below:./mvnw clean spring-boot:run --projects movie-ui 
- 
In a terminal, inside the springboot-aws-localstack-opensearch-s3-secretsmanagerroot folder, run the following script:./build-docker-images.sh 
- 
- 
movie-api In a terminal, run the following command: docker run --rm --name movie-api -p 9080:9080 \ -e AWS_REGION=eu-west-1 -e AWS_ACCESS_KEY_ID=key -e AWS_SECRET_ACCESS_KEY=secret \ --network=springboot-aws-localstack-opensearch-s3-secretsmanager_default \ ivanfranchin/movie-api:1.0.0 
- 
movie-ui In another terminal, run the command below: docker run --rm --name movie-ui -p 9081:9081 \ -e MOVIE_API_URL=http://movie-api:9080 \ --network=springboot-aws-localstack-opensearch-s3-secretsmanager_default \ ivanfranchin/movie-ui:1.0.0 
 
- 
| Application | Type | URL | 
|---|---|---|
| movie-api | Swagger | http://localhost:9080/swagger-ui.html | 
| movie-api | UI | http://localhost:9080 | 
| movie-ui | UI | http://localhost:9081 | 
- 
Adding movie: in the GIF below, we are using movie-apito add the movie "American Pie 2"
- 
Searching movies: in the GIF below, we are using movie-uito search for movies
- 
OpenSearch Check indexes curl "http://localhost.localstack.cloud:4566/opensearch/eu-west-1/my-domain/_cat/indices?v"Simple search curl "http://localhost.localstack.cloud:4566/opensearch/eu-west-1/my-domain/movies/_search?pretty"
- To stop the applications, go to the terminal where they are running and press Ctrl+C;
- To stop and remove Docker Compose containers, network, and volumes, go to a terminal and, inside the springboot-aws-localstack-opensearch-s3-secretsmanagerroot folder, run the following command:docker compose down -v 
To remove the Docker images created by this project, go to a terminal and, inside the springboot-aws-localstack-opensearch-s3-secretsmanager root folder, run the script below:
./remove-docker-images.sh

