Spring boot + AWS Comprehend + AWS RDS + Heroku (Part 2)

Extracting insights from text data and storing it in database with corresponding user metadata

Amit Singh
3 min readAug 30, 2021

Part 2…
Here we are, and in this part we are going to:

  • provision an AWS RDS MySQL database and connect our spring boot app to it.
  • deploy the spring boot app on Heroku

Creating AWS RDS MySQL database

Follow this guide to provision your database first.

While creating the database resource you can create a new DB and setup credentials to connect to the database with. Make a note of the DB name and the credentials.

Make sure there are no firewall/network rules set that might block the connectivity. Since this is just a test environment, I update the security group configuration to set the inbound traffic rule to allow all incoming traffic.

traffic rules to allow all inbound traffic

Now get the endpoint to the DB to create the connection string.

Sample endpoint

Update the application.properties file to include the new:

  • spring.datasource.url
  • spring.datasource.username
  • spring.datasource.password

properties.

Spring Boot deployment on Heroku

Follow this guide to deploy the spring boot app.
You need to create a new Heroku app using the heroku create <app name> command.

Before pushing the code to heroku though, we need to make few modifications, viz:

  • server.port=${PORT:8080}
    add this mapping in the application.properties file to accept and redirect traffic to the port the app is running on (I’m using the default one so 8080 here)
  • run gradle assemble to generate a jar file for the project.
    It should create a snapshot jar file in the build/libs/ directory.
  • now create a Procfile in the project’s root directory where we refer to jar created in the previous step. In my case, I had this:

web: java $JAVA_OPTS -jar build/libs/person-attribute-0.0.1-SNAPSHOT.jar -Dserver.port=8080 $JAR_OPTS

  • I also had to create a system.properties file in the project’s root directory to specify the java version I was using:

java.runtime.version=11

Now we can finally deploy the app on heroku. Push the code and make sure to check that the app is running on the correct port by checking the logs using the heroku logs — tail command.

And that’s it.

We now have a Spring Boot app, deployed on Heroku, that uses AWS Comprehend to analyze text data, then stores the extracted insights in an AWS RDS database.

The base url for my heroku app is: https://person-attribute.herokuapp.com/

list users in my database

Feel free to use it for your tests.

If you have any questions or suggestions, please do drop them in the comments section below.
See you on another post 🖖

Hey there 👋. If I helped you in some way and you’re feeling generous today, you can now buy me a coffee!

--

--

Amit Singh
Amit Singh

Written by Amit Singh

A Software Engineer who believes that technological progress should be more about extension than replacement.

No responses yet