In this section, you will launch an Amazon RDS PostgreSQL database instance, connecting it directly with the EC2 compute instance in the VPC private subnets to store data for the Rookwork project.
Before starting, make sure that you have created the necessary Security Groups. See the detailed instructions in Part 3 – Create Security Groups (Step 1) of article 5.3.
Once the network and EC2 instance are ready, start creating the relational database instance:

db.t4g.micro, 2 vCPUs, 1 GiB RAM, 20 GiB Storage).rookwork-db).postgres.
rookwork-ec2-1 / i-035c5645906cef43f).rds-ec2-X for the database and ec2-rds-X for the EC2 instance). This automatically permits secure traffic from your EC2 instance to the RDS Database port without requiring manual routing rules.
To enable the Spring Boot application running on the EC2 instance to connect to the Amazon RDS PostgreSQL database, update the project configuration file:
src/main/resources/application.properties (or application.yml) in your project source code.spring.datasource.url=jdbc:postgresql://rookwork-db.cxegees2u15z.ap-southeast-1.rds.amazonaws.com:5432/postgres
spring.datasource.username=postgres
spring.datasource.password=your_password_here
spring.datasource.driver-class-name=org.postgresql.Driver
spring.jpa.hibernate.ddl-auto=update
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.show-sql=true
Note: The configurations above are temporary settings for checking local connectivity. Later, we will optimize this configuration by utilizing environment variables in the CI/CD pipeline to secure sensitive connection credentials.
Once the RDS database status changes to Available, execute the following steps from the EC2 instance to verify the connection:
psql (PostgreSQL Client) utility on the EC2 instance:sudo dnf install -y postgresql15
psql -h <RDS_ENDPOINT> -U postgres -d postgres
<RDS_ENDPOINT> with the actual RDS instance Endpoint found on the AWS RDS Console details page)postgres=>, it proves that the EC2 instance has successfully connected to the RDS PostgreSQL database through the VPC internal network.
Note: The image above illustrates a successful terminal session connection. This test and installation ensure that your application running on EC2 can successfully communicate with and securely store data in the RDS PostgreSQL database.