|
| 1 | +# Shipment List Demo Application - AWS in PROD and LocalStack on DEV environment |
| 2 | + |
| 3 | +### Prerequisites |
| 4 | +- Maven 3.8.5 & Java 17 |
| 5 | +- AWS free tier account |
| 6 | +- Docker - for running LocalStack |
| 7 | +- AWS Command Line Interface - for managing your services |
| 8 | +- npm - for running the frontend app |
| 9 | + |
| 10 | +## Purpose |
| 11 | + |
| 12 | +This application was conceived for demonstration purposes to highlight the ease of switching from |
| 13 | +using actual AWS dependencies to having them emulated on LocalStack for your *developer environment*. |
| 14 | +Of course this comes with other advantages, but the first focus point is making the transition. |
| 15 | + |
| 16 | +## What it does |
| 17 | + |
| 18 | +*shipment-list-demo* is a Spring Boot application dealing with CRUD operations an employee can execute |
| 19 | +on a bunch of shipments that they're allowed to view - think of it like the Post app. |
| 20 | +The demo consists of a backend and a frontend implementation, using React to display the information. |
| 21 | +The AWS services involved are: |
| 22 | + - S3 for storing pictures |
| 23 | + - DynamoDB for the entities |
| 24 | + - Lambda function that will validate the pictures. |
| 25 | + |
| 26 | +## How it works |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | +## How we will be using it |
| 31 | +We’ll be walking through a few scenarios using the application, and we expect it to maintain the |
| 32 | +behavior in both production and development environments. |
| 33 | +We’ll take advantage of one of the core features of the Spring framework that allows us to bind our |
| 34 | +beans to different profiles, such as dev, test, and prod. Of course, these beans need to know how to |
| 35 | +behave in each environment, so they’ll get that information from their designated configuration files, |
| 36 | +`application-prod.yml`, and `application-dev.yml`. |
| 37 | + |
| 38 | +## Running it |
| 39 | + |
| 40 | +### Production simulation |
| 41 | + |
| 42 | +Now we don’t have a real production environment because that’s not the point here, but most likely, |
| 43 | +an application like this runs on a container orchestration platform, and all the necessary configs |
| 44 | +are still provided. Since we’re only simulating a production instance, all the configurations are |
| 45 | +kept in the `application-prod.yml` file. |
| 46 | + |
| 47 | +Before getting started, it's important to note that an IAM user, who's credentials will be used, |
| 48 | +needs to be created with the following policies: |
| 49 | +- AmazonS3FullAccess |
| 50 | +- AWSLambda_FullAccess |
| 51 | +- AmazonDynamoDBFullAccess |
| 52 | + |
| 53 | +The `scripts/new-bucket.sh` script will create the necessary S3 resource. |
| 54 | + |
| 55 | +At startup @dynamobee helps set up the table we need and populate it with some sample data. |
| 56 | +@dynamobee is library for tracking, managing, and applying database changes |
| 57 | +The changelog acts as a database version control. It tracks all the changes made to the database, |
| 58 | +and helps you manage database migration. |
| 59 | + |
| 60 | +To run the backend simply use |
| 61 | +``` |
| 62 | +mvn spring-boot:run -Dspring-boot.run.profiles=prod |
| 63 | +``` |
| 64 | + |
| 65 | +Now `cd` into `src/main/shipment-list-frontend` and run `npm install` and `npm start`. |
| 66 | +This will spin up the React app that can be accessed on `localhost:3000`. |
| 67 | + |
| 68 | +You should now be able to see a list of shipments with standard icons, that means that only the database |
| 69 | +is populated, the pictures still need to be added from the `sample-pictures` folder. |
| 70 | +The weight of a shipment we can perceive, but not the size, that's why we need to display it, |
| 71 | +using the "banana for scale" measuring unit. How else would we know?? |
| 72 | + |
| 73 | +The Lambda function is still not up. This falls under the `shipment-list-lambda-validator` project. |
| 74 | +``` |
| 75 | +git clone https://github.com/tinyg210/shipment-list-lambda-validator.git |
| 76 | +``` |
| 77 | + |
| 78 | +The `create-lambda.sh` script will do everything that needs for the creation and configuration of the |
| 79 | +Lambda. (I know what you're thinking, Terraform will follow.) |
| 80 | +Run `add-notif-config-for-lambda.sh`, but before that remember to edit `notification-config.json` with |
| 81 | +your own AWS account ID. This will enable the Lambda to receive notifications every time a picture is being |
| 82 | +added to S3. |
| 83 | + |
| 84 | +You should now be able to add a new picture for each shipment. Files that are not pictures will be deleted |
| 85 | +and the shipment picture will be replaced with a generic icon. |
| 86 | + |
| 87 | +### Developer environment |
| 88 | + |
| 89 | +To switch to using LocalStack instead of AWS services just run `docker compose up` to spin up a Localstack |
| 90 | +container. |
| 91 | +After that, the Spring Boot application needs to start using the dev profile: |
| 92 | +``` |
| 93 | +mvn spring-boot:run -Dspring-boot.run.profiles=dev |
| 94 | +``` |
| 95 | + |
| 96 | +This should again populate the DynamoDB, this time on LocalStack. |
| 97 | +From here on, the rest of the steps are the same, but all the scripts that need to run end in `-local`, |
| 98 | +as they use the `awslocal` CLI. |
| 99 | + |
| 100 | +The same actions should be easily achieved again, but locally. |
| 101 | + |
| 102 | + |
0 commit comments