@@ -32,7 +32,7 @@ Of course this comes with other advantages, but the first focus point is making
3232
3333#### What it does
3434
35- * shipment-list-demo* is a Spring Boot application dealing with CRUD operations an employee can
35+ * shipment-list-demo* is a Spring Boot application dealing with CRUD operations a person can
3636execute
3737on a bunch of shipments that they're allowed to view - think of it like the Post app.
3838The demo consists of a backend and a frontend implementation, using React to display the
@@ -49,20 +49,64 @@ The AWS services involved are:
4949#### How to use it
5050
5151We’ll be walking through a few scenarios using the application, and we expect it to maintain the
52- behavior in both production and development environments. This behaviour can be "scientifically"
53- backed up
54- by adding integration tests.
52+ behavior in both production (AWS) and development (LocalStack) environments.
5553
5654We’ll take advantage of one of the core features of the Spring framework that allows us to bind our
5755beans to different profiles, such as dev, test, and prod. Of course, these beans need to know how to
5856behave in each environment, so they’ll get that information from their designated configuration
5957files, ` application-prod.yml ` , and ` application-dev.yml ` .
6058
59+ #### Terraform
60+
61+ The Terraform configuration file will create the needed S3 bucket, the DynamoDB ` shipment ` table and populate it with some
62+ sample data, the Lambda function that will help with the picture processing (make sure you create the jar),
63+ the SQS and SNS which will bring back the notification when the processing is finished.
64+
65+
6166## Instructions
6267
68+ ### Only run once
69+
70+ The following instructions only need to run once, weather you choose to run both cases, on AWS and
71+ LocalStack, or just jump straight to LocalStack.
72+
73+ ### Building the validator module
74+
75+ Step into the ` shipment-picture-lambda-validator ` module and run ` mvn clean package shade:shade ` .
76+ This will create an uber-jar by packaging all its dependencies. We'll need this one in the next
77+ steps. We can keep the same jar for both running on AWS and LocalStack.
78+
79+
80+ ### Running the GUI
81+
82+ ` cd ` into ` src/main/shipment-list-frontend ` and run ` npm install ` and ` npm start ` .
83+ This will spin up the React app that can be accessed on ` localhost:3000 ` .
84+ You'll only see the title, as the backend is not running yet to provide the list of shipments.
85+
86+ For running it on Windows, there are some
87+ [ extra requirements] ( https://learn.microsoft.com/en-us/windows/dev-environment/javascript/react-on-windows )
88+ ,
89+ but no worries, it should be straightforward.
90+
91+ #### How to use the GUI
92+
93+ After starting the backend, refreshing the React app will fetch a list of shipments.
94+ The weight of a shipment is already given, but not the size, that's why we need pictures to
95+ understand it better, using the "banana for scale" measuring unit. How else would we know??
96+
97+ Current available actions using the GUI:
98+
99+ - upload a new image
100+ - delete shipment from the list
101+ - create and update shipment are available only via Postman (or any other API platform)
102+
103+ Files that are not pictures will be deleted
104+ and the shipment picture will be replaced with a generic icon, because we don't want any trouble.
105+
106+
63107## Running on AWS
64108
65- Now, we don’t have a real production environment because that’s not the point here, but most likely,
109+ Now, we don’t have a real production environment because that’s not the point here, but most likely
66110an application like this runs on a container orchestration platform, and all the necessary configs
67111are still provided. Since we’re only simulating a production instance, all the configurations are
68112kept in the ` application-prod.yml ` file.
@@ -80,6 +124,7 @@ needs to be created with the following policies:
80124- AWSLambdaExecute
81125- AmazonS3ObjectLambdaExecutionRolePolicy
82126
127+ For simplicity, we chose to use full access to all the services, so we don't have to add new permissions later on.
83128We will be using the user's credentials and export them as temporary environment variables with the
84129` export ` (` set ` on Windows) command:
85130
@@ -88,12 +133,6 @@ $ export AWS_ACCESS_KEY_ID=[your_aws_access_key_id]
88133$ export AWS_SECRET_ACCESS_KEY=[your_aws_secret_access_key_id]
89134```
90135
91- ### Building the validator module
92-
93- Step into the ` shipment-picture-lambda-validator ` module and run ` mvn clean package shade:shade ` .
94- This will create an uber-jar by packaging all its dependencies. We'll need this one in the next
95- step.
96-
97136### Creating resources - running Terraform
98137
99138Make sure you have Terraform [ installed] ( https://developer.hashicorp.com/terraform/downloads )
@@ -110,19 +149,9 @@ Once these 2 commands run successfully and no errors occur, it's time to run:
110149```
111150$ terraform apply
112151```
152+ If everything finishes successfully, the AWS services should be up and running.
113153
114- This should create the needed S3 bucket, the DynamoDB ` shipment ` table and populate it with some
115- sample data, the Lambda function that will help with picture validation, the SQS and SNS.
116-
117- ### Running the GUI
118-
119- Now ` cd ` into ` src/main/shipment-list-frontend ` and run ` npm install ` and ` npm start ` .
120- This will spin up the React app that can be accessed on ` localhost:3000 ` .
121-
122- For running it on Windows, there are some
123- [ extra requirements] ( https://learn.microsoft.com/en-us/windows/dev-environment/javascript/react-on-windows )
124- ,
125- but no worries, it should be straightforward.
154+ ### Starting the backend
126155
127156Go back to the root folder and run the backend simply by using
128157
@@ -137,32 +166,23 @@ Notice the `prod` profile is being set via command line arguments.
137166At ` localhost:3000 ` you should now be able to see a list of shipments with standard icons,
138167that means that only the database is populated, the pictures still need to be added from the
139168` sample-pictures ` folder.
169+ You can now interact with the application using the React app. All services used in the backend are
170+ running on the real AWS cloud.
140171
141- The weight of a shipment is already given, but not the size, that's why we need pictures to
142- understand it better,
143- using the "banana for scale" measuring unit. How else would we know??
144172
145- Current available actions using the GUI:
146-
147- - upload a new image
148- - delete shipment from the list
149- - create and update shipment are available only via Postman (or any other API platform)
173+ Before moving on, make sure you clean up your AWS resources by running (also in setup/terraform):
150174
151- Files that are not pictures will be deleted
152- and the shipment picture will be replaced with a generic icon, because we don't want any trouble.
175+ ```
176+ $ terraform destroy
177+ ```
153178
154179## Running on LocalStack
155180
156181
157182To switch to using LocalStack instead of AWS services just run ` docker compose up ` in the root
158- folder
159- to spin up a Localstack container.
183+ folder to spin up a Localstack container.
160184
161- Before we proceed, make sure you clean up your AWS resources by running
162-
163- ```
164- $ terraform destroy
165- ```
185+ ### Creating resources on LocalStack
166186
167187To generate the exact same resources on LocalStack, we need ` tflocal ` , a thin wrapper script around
168188the terraform command line client. ` tflocal ` takes care of automatically configuring the local
@@ -185,18 +205,20 @@ Usage: terraform [global options] <subcommand> [args]
185205...
186206```
187207
188- From here on, it's smooth sailing, the same as before . In the ` setup/terraform ` folder, run the ` cleanup ` script
208+ From here on, it's the same as using AWS . In the ` setup/terraform ` folder, run the ` cleanup ` script
189209to get rid of any files that keep track of the resources' state. Then:
190210
191211```
192212$ tflocal init
193- $ tflocal plan -var 'env=dev
213+ $ tflocal plan -var 'env=dev'
194214$ tflocal apply
195215```
196216
197217What we're doing here is just passing an environmental variable to let the Lambda
198218know this is the ` dev ` environment.
199219
220+ ### Running the backend
221+
200222After that, the Spring Boot application needs to start using the dev profile (make sure you're in
201223the
202224root folder):
0 commit comments