Code Monkey home page Code Monkey logo

ivangfr / springboot-aws-localstack-opensearch-s3-secretsmanager Goto Github PK

View Code? Open in Web Editor NEW
8.0 2.0 4.0 20.69 MB

In this project, we are going to use LocalStack to simulate locally, some services provided by AWS Cloud such as OpenSearch, S3, and Secrets Manager. Also, in order to simplify the use of AWS managed services, we are going to use Spring Cloud AWS.

Shell 4.19% Java 71.71% JavaScript 0.35% HTML 23.74%
aws localstack spring-boot thymeleaf aws-opensearch aws-s3 aws-secrets-manager java jib omdb-api

springboot-aws-localstack-opensearch-s3-secretsmanager's Introduction

springboot-aws-localstack-opensearch-s3-secretsmanager

In this project, we are going to use LocalStack to simulate locally, some services provided by AWS Cloud such as OpenSearch, S3, and Secrets Manager. Also, in order to simplify the use of AWS managed services, we are going to use Spring Cloud AWS.

Note: Check out the springboot-aws-localstack-dynamodb-lambda-sns-sqs repository. In it, we've developed two Spring Boot applications for producing and listening to news updates. We also utilized LocalStack to locally simulate AWS Cloud services like DynamoDB, Lambda, SNS and SQS.

Proof-of-Concepts & Articles

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.

Additional Readings

Project Diagram

project-diagram

Applications

  • movie-api

    Spring Boot Java 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}/uploadPoster
    

    The information of the movies, such as imdb, title, year, etc, are stored in OpenSearch that is hosted in LocalStack. The movie's poster are stored in S3 buckets.

    The movie-api has access to OMDb API to search and add easily new movies. In order to make request to OMDb API, an apiKey is needed. This key is stored as a secret in Secrets Manager.

  • movie-ui

    Spring Boot Java Web application with a user interface designed for searching movies indexed in movie-api. To populate its UI with movie data, movie-ui communicates with movie-api by making requests to its endpoints. The movie’s poster is retrieved from the S3 bucket.

Prerequisites

Start and Initialize LocalStack

  • In a terminal, make sure you are in inside springboot-aws-localstack-opensearch-s3-secretsmanager root folder

  • Start LocalStack Docker container

    DEBUG=1 docker compose up -d
    
  • [Optional] Debug logs are enabled so that we have more insights about what is happening. To monitor localstack Docker container logs, run the command below

    docker logs localstack -f
    
  • Initialize LocalStack by running the following script

    ./init-localstack.sh <OMDB_API_KEY>
    

    The script requires OMDB_API_KEY as first and unique argument. The script will create:

    • a domain for OpenSearch as well as the movies index using the movies-settings.json provided;
    • bucket com.ivanfranchin.movieapi.posters in S3;
    • a secret for OMDB_API_KEY in Secrets Manager.

Running applications with Maven

  • movie-api

    In a terminal and, inside springboot-aws-localstack-opensearch-s3-secretsmanager root 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 springboot-aws-localstack-opensearch-s3-secretsmanager root folder, run the command below

    ./mvnw clean spring-boot:run --projects movie-ui
    

Running applications as Docker container

  • Build Docker images

    In a terminal and, inside springboot-aws-localstack-opensearch-s3-secretsmanager root folder, run the following script

    ./docker-build.sh
    
  • Run Docker containers

    • 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 URL

Application Type URL
movie-api Swagger http://localhost:9080/swagger-ui.html
movie-api UI http://localhost:9080
movie-ui UI http://localhost:9081

Demo

  • Adding movie: in the GIF below, we are using movie-api to add the movie "American Pie 2"

    demo-adding-movie

  • Searching movies: in the GIF below, we are using movie-ui to search for movies

    demo-searching-movies

Useful Links

  • 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"
    

Shutdown

  • 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 springboot-aws-localstack-opensearch-s3-secretsmanager root folder, run the following command
    docker compose down -v
    

Cleanup

To remove the Docker images created by this project, go to a terminal and, inside springboot-aws-localstack-opensearch-s3-secretsmanager root folder, run the script below

./remove-docker-images.sh

springboot-aws-localstack-opensearch-s3-secretsmanager's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.