AWS DEVOPS, part 1: How to connect to AWS RDS PostgreSQL) from SpringBoot

Image for post
Image for post

Connecting to AWS resources can be sometimes tricky. One of such resource is RDS. It is the least fancy name of AWS resource, and stands for Relational Database Service.

To connect to the database you need to gather:

  • endpoint
  • port
  • user
  • password
  • database name

To gather these go to RDS, and choose “Databases” in left menu.

Next, choose the database you are interested in.

We will be looking at two tabs you see now, that is “Connectivity and Security” and “Configuration”.

In “Connectivity and Security” you will find endpoint and port.

In “Configuration” you will find “master username”. This is the username we need.

Word of caution here: in reality you should not use master user account to connect to the database because it is insecure. But if you want to test your connection it is easy way to go further.

Password for the master user name is set when creating the database. So you can have it, or DevOps. Someone should have it. If not, you can reset it easily in a way described here.

Word of caution here: if anyone uses current password he wont be able to access the database anymore with old password.

Also in “Configuration” you will find the desired database name under “DB name”.

So now, when you have endpoint, port, user, password and database name, we can start setting up connection.

First i strongly advice you to download pgAdmin. It is a nice PostreSQL database management tool.

You put your endpoint URL there, and also: login, password, port number and database name. If you are connected, you can move to set up your SpringBoot connection.

Why i can not connect?
There may be a lots of reasons why you can not connect. Most importantly check security rules. It is possible you have to add a rule to allow yourself access to the database

Below i have shown how your SpringBoot configuration should look like, in most important part:

spring.datasource.url=jdbc:postgresql://<endpoint>:<port>/<database name>
spring.datasource.username=<user>
spring.datasource.password=<password>

As you can see, you consume here your endpoint, port and database name in spring.datasource.url, and provide user name and password with two separate properties.

Off you go, and now, you should connect to AWS RDS PostgreSQL database from SpringBoot code.

Please clap and follow for more articles about AWS DevOps for regular developers!

Written by

Senior software development consultant. Programming for 20 years. TOP 2% of StackOverflow users. 2 million views on Quora. Currently Angular, TypeScript etc

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store