AWS DEVOPS, part 1: How to connect to AWS RDS PostgreSQL) from SpringBoot
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:
- 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:
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!