Enterprise JavaJava

Spring Data JPA Switch to AWS RDS Proxy Example

1. Introduction

AWS RDS Proxy is a fully managed, highly available database proxy for Amazon Relational Database Service(RDS). It sits between the application and the relational database to manage connections to the database and provides better scaling, resilience, and security. In this example, I will show the changes needed in a Spring Data JPA project when connecting to AWS RDS Proxy instead of the Postgres Database directly.

2. Setup

In this step, I will create a Spring Data JPA project via Spring Initializer.

2.1 Build.gradle

In this step, I will add the AWS RDS libraries.

build.gradle

plugins {
	id 'java'
	id 'org.springframework.boot' version '3.5.7'
	id 'io.spring.dependency-management' version '1.1.7'
}

group = 'org.jcg.zheng.demo'
version = '0.0.1-SNAPSHOT'
description = 'Demo project for Spring Boot'

java {
	toolchain {
		languageVersion = JavaLanguageVersion.of(21)
	}
}

repositories {
	mavenCentral()
}

dependencies {
	implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
	
	// https://mvnrepository.com/artifact/software.amazon.awssdk/rds
	implementation("software.amazon.awssdk:rds:2.38.2")
	// https://mvnrepository.com/artifact/software.amazon.awssdk/auth
	implementation("software.amazon.awssdk:auth:2.38.2")

	runtimeOnly 'org.postgresql:postgresql'
	testImplementation 'org.springframework.boot:spring-boot-starter-test'
	testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}

tasks.named('test') {
	useJUnitPlatform()
}
  • Line 25 and 27: libraries are needed for the AWS RDS Proxy.

2.2 AwsRdsProxyApplication

No change to the generated AwsRdsProxyApplication.java.

AwsRdsProxyApplication.java

package org.jcg.zheng.demo.aws_rds_proxy;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class AwsRdsProxyApplication {

	public static void main(String[] args) {
		SpringApplication.run(AwsRdsProxyApplication.class, args);
	}

}

2.3 Demo Entity

In this step, I will create a DemoEntity.java.

DemoEntity.java

package org.jcg.zheng.demo.aws_rds_proxy.entity;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.Table;

@Entity
@Table(name = "TABLE_1")
public class DemoEntity {

	@Id
	@GeneratedValue
	private Integer id;

	private String name;

	public Integer getId() {
		return id;
	}

	public String getName() {
		return name;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public void setName(String name) {
		this.name = name;
	}

}

3. DataSource Configuration

In this step, I will create two data source configurations: one for localdev that connects to the database directly, the other for prod that connects to RDS Proxy.

3.1 LocalDataSourceConfig

In this step, I will create a LocalDataSourceConfig.java that connects to the Postgres database directly for the localdev profile.

LocalDataSourceConfig.java

package org.jcg.zheng.demo.aws_rds_proxy.config;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

@Configuration
@Profile("localdev")
public class LocalDataSourceConfig {

	@Value("${spring.datasource.url}")
	private String url;

	@Value("${spring.datasource.username}")
	private String dbUsername;

	@Value("${spring.datasource.password}")
	private String dbPassword;

	@Bean
	@ConfigurationProperties(prefix = "spring.datasource.hikari")
	public DataSource dataSource() {
		return DataSourceBuilder.create().url(url).username(dbUsername).password(dbPassword).build();
	}

}
  • Line 28: The url, dbUsername, and password are defined in the application-localdev.yaml.

3.2 AWS RDS Proxy DataSourceConfig

In this example, I will create the ProxyDataSourceConfig that connects to RDS Proxy via IAM auth token.

ProxyDataSourceConfig.java

package org.jcg.zheng.demo.aws_rds_proxy.config;

import java.sql.SQLException;
import java.util.concurrent.atomic.AtomicReference;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import com.zaxxer.hikari.HikariDataSource;

import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.rds.RdsUtilities;

@Configuration
@EnableScheduling
@Profile("prod")
public class ProxyDataSourceConfig {

	@Value("${spring.datasource.url}")
	private String url;

	@Value("${spring.datasource.username}")
	private String dbUsername;

	@Value("${spring.datasource.password}")
	private String dbPassword;

	@Value("${aws.rds.proxy.host}")
	private String host;
	@Value("${aws.rds.proxy.port}")
	private int port;

	@Value("${aws.region}")
	private String region;

	private AtomicReference<String> currentToken = new AtomicReference<>();
	private DataSource dataSource;

	@Bean
	@ConfigurationProperties(prefix = "spring.datasource.hikari")
	public DataSource dataSource() {
		getIamAuthToken();

		dataSource = DataSourceBuilder.create().url(url).username(dbUsername).password(currentToken.get()).build();

		return dataSource;
	}

	private void getIamAuthToken() {
		RdsUtilities rdsUtilities = RdsUtilities.builder().region(Region.of(region)).build();

		String authToken = rdsUtilities
				.generateAuthenticationToken(b -> b.hostname(host).port(port).username(dbUsername));
		currentToken.set(authToken);
	}

	private void refreshHikariPool(HikariDataSource hikariDatasource) {
		hikariDatasource.getHikariConfigMXBean().setPassword(currentToken.get());

		try {
			hikariDatasource.evictConnection(hikariDatasource.getConnection());
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	@Scheduled(fixedRate = 10 * 60 * 1000) // every 10 minutes
	public void refreshIamToken() {
		getIamAuthToken();

		if (dataSource != null && dataSource instanceof HikariDataSource hikariDataSoure) {
			refreshHikariPool(hikariDataSoure);
		}
	}
}
  • Line 44: RDS Proxy is set up to connect with IAM auth token. It expires every 15 minutes and AtomicReference<String> currentToken holds its current value.
  • Line 45: define datasource as a class member because IAM auth token refreshes periodically.
  • Kine 52: the Datasource‘s password is set by the currentToken value.
  • Line 62: generate the IAM auth token via RdsUtilities and set the value in the currentToken.
  • Line 65, 66: the refreshHikariPool method sets the password by the currentToken for a new connection and evictConnection for the existing connection.
  • Line 75, 76: schedule a job to refreshIamToken every 10 minutes,

4. Application Configuration

In this step, I will create three application YAML files:

  • application.yaml for common configurations.
  • applicaiton-localdev.yaml for connecting to the database directly.
  • application-prod.yaml for connecting to the RDS proxy.

4.1 Application Common Configuration

The application.yaml defines the common properties.

application.yaml

# application.yaml
logging:
  level:
    root: INFO
    com.zaxxer.hikari: DEBUG
    org.hibernate.SQL: DEBUG

spring:
  application:
    name: aws-rds-proxy
  jpa:
    open-in-view: false
    show-sql: true
    hibernate:
      ddl-auto: update
    properties:
      hibernate:
        default_schema: marydb
        format_sql: true
  profiles:
    active: localdev

4.2 Application Localdev Configuration

The application-localdev.yaml file defines the datasource connection properties for localdev.

application-localdev.yaml

# application-localdev.yaml

spring:
  config:
    activate:
      on-profile: localdev

  datasource:
    url: jdbc:postgresql://localhost:5432/postgres
    username: postgres
    password: zheng22
    hikari:
      pool-name: localHikariPool
  • Line 9: the url is the actual database connection url.
  • Line 13: leave hikari pool configuration with the default value except the pool-name.

4.3 AWS RDS Proxy Configuration

The application-prod.yaml defines the RDS Proxy properties.

application-prod.yaml

# application-prod.yaml

spring:
  config:
    activate:
      on-profile: prod

spring:
  datasource:
    url: jdbc:postgresql://mydb-proxy.proxy-abcdefgh1234.us-east-1.rds.amazonaws.com:5432/postgres
    username: proxyUser
    hikari:      
      minimum-idle: 0                  # minimum idle connections, no need for proxy as IAM auth token refreshes   
      max-lifetime: 110000             # 1 minute 50 seconds (when Proxy Idle Connection time is 2min)
      pool-name: RdsProxyHikariPool

aws:
  region: us-east-1
  rds:
    proxy:
      host: mydb-proxy.proxy-abcdefgh1234.us-east-1.rds.amazonaws.com
      port: 5432

  • Line 10: the url is the proxy endpoint.
  • Line 13: the hikari minimum-idle defaults to 10. Set to 0 as IAM auth token expires.
  • Line 14: the hikari max-lifetime defaults to 30 minutes. It needs to be less than Proxy’s Idle Client Connection Timeout.
  • Line 21, 22: the AWS Proxy host and port are used to generate IAM auth token.

5. Start LocalDev

In this step, I will start the Spring Data JPA project for localdev and capture the server log.

Server Log

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/

 :: Spring Boot ::                (v3.5.7)

2025-11-16T10:41:12.937-06:00  INFO 28284 --- [aws-rds-proxy] [           main] o.j.z.d.a.AwsRdsProxyApplication         : Starting AwsRdsProxyApplication using Java 21.0.8 with PID 28284 (C:\MaryZheng\workspace\aws-rds-proxy\bin\main started by zzhen in C:\MaryZheng\workspace\aws-rds-proxy)
2025-11-16T10:41:12.941-06:00  INFO 28284 --- [aws-rds-proxy] [           main] o.j.z.d.a.AwsRdsProxyApplication         : The following 1 profile is active: "localdev"
2025-11-16T10:41:13.334-06:00  INFO 28284 --- [aws-rds-proxy] [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2025-11-16T10:41:13.361-06:00  INFO 28284 --- [aws-rds-proxy] [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 16 ms. Found 0 JPA repository interfaces.
2025-11-16T10:41:13.593-06:00 DEBUG 28284 --- [aws-rds-proxy] [           main] com.zaxxer.hikari.HikariConfig           : Class org.postgresql.Driver found in Thread context class loader jdk.internal.loader.ClassLoaders$AppClassLoader@5c647e05
2025-11-16T10:41:13.680-06:00  INFO 28284 --- [aws-rds-proxy] [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
2025-11-16T10:41:13.719-06:00  INFO 28284 --- [aws-rds-proxy] [           main] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 6.6.33.Final
2025-11-16T10:41:13.749-06:00  INFO 28284 --- [aws-rds-proxy] [           main] o.h.c.internal.RegionFactoryInitiator    : HHH000026: Second-level cache disabled
2025-11-16T10:41:13.973-06:00  INFO 28284 --- [aws-rds-proxy] [           main] o.s.o.j.p.SpringPersistenceUnitInfo      : No LoadTimeWeaver setup: ignoring JPA class transformer
2025-11-16T10:41:13.991-06:00 DEBUG 28284 --- [aws-rds-proxy] [           main] com.zaxxer.hikari.HikariConfig           : localHikariPool - configuration:
2025-11-16T10:41:13.997-06:00 DEBUG 28284 --- [aws-rds-proxy] [           main] com.zaxxer.hikari.HikariConfig           : allowPoolSuspension.............false
2025-11-16T10:41:13.997-06:00 DEBUG 28284 --- [aws-rds-proxy] [           main] com.zaxxer.hikari.HikariConfig           : autoCommit......................true
2025-11-16T10:41:13.997-06:00 DEBUG 28284 --- [aws-rds-proxy] [           main] com.zaxxer.hikari.HikariConfig           : catalog.........................none
2025-11-16T10:41:13.997-06:00 DEBUG 28284 --- [aws-rds-proxy] [           main] com.zaxxer.hikari.HikariConfig           : connectionInitSql...............none
2025-11-16T10:41:13.997-06:00 DEBUG 28284 --- [aws-rds-proxy] [           main] com.zaxxer.hikari.HikariConfig           : connectionTestQuery.............none
2025-11-16T10:41:14.000-06:00 DEBUG 28284 --- [aws-rds-proxy] [           main] com.zaxxer.hikari.HikariConfig           : connectionTimeout...............30000
2025-11-16T10:41:14.000-06:00 DEBUG 28284 --- [aws-rds-proxy] [           main] com.zaxxer.hikari.HikariConfig           : credentials.....................com.zaxxer.hikari.util.Credentials@41f4039e
2025-11-16T10:41:14.002-06:00 DEBUG 28284 --- [aws-rds-proxy] [           main] com.zaxxer.hikari.HikariConfig           : dataSource......................none
2025-11-16T10:41:14.002-06:00 DEBUG 28284 --- [aws-rds-proxy] [           main] com.zaxxer.hikari.HikariConfig           : dataSourceClassName.............none
2025-11-16T10:41:14.002-06:00 DEBUG 28284 --- [aws-rds-proxy] [           main] com.zaxxer.hikari.HikariConfig           : dataSourceJNDI..................none
2025-11-16T10:41:14.002-06:00 DEBUG 28284 --- [aws-rds-proxy] [           main] com.zaxxer.hikari.HikariConfig           : dataSourceProperties............{password=}
2025-11-16T10:41:14.003-06:00 DEBUG 28284 --- [aws-rds-proxy] [           main] com.zaxxer.hikari.HikariConfig           : driverClassName................."org.postgresql.Driver"
2025-11-16T10:41:14.003-06:00 DEBUG 28284 --- [aws-rds-proxy] [           main] com.zaxxer.hikari.HikariConfig           : exceptionOverride...............none
2025-11-16T10:41:14.003-06:00 DEBUG 28284 --- [aws-rds-proxy] [           main] com.zaxxer.hikari.HikariConfig           : exceptionOverrideClassName......none
2025-11-16T10:41:14.003-06:00 DEBUG 28284 --- [aws-rds-proxy] [           main] com.zaxxer.hikari.HikariConfig           : healthCheckProperties...........{}
2025-11-16T10:41:14.003-06:00 DEBUG 28284 --- [aws-rds-proxy] [           main] com.zaxxer.hikari.HikariConfig           : healthCheckRegistry.............none
2025-11-16T10:41:14.004-06:00 DEBUG 28284 --- [aws-rds-proxy] [           main] com.zaxxer.hikari.HikariConfig           : idleTimeout.....................600000
2025-11-16T10:41:14.004-06:00 DEBUG 28284 --- [aws-rds-proxy] [           main] com.zaxxer.hikari.HikariConfig           : initializationFailTimeout.......1
2025-11-16T10:41:14.004-06:00 DEBUG 28284 --- [aws-rds-proxy] [           main] com.zaxxer.hikari.HikariConfig           : isolateInternalQueries..........false
2025-11-16T10:41:14.004-06:00 DEBUG 28284 --- [aws-rds-proxy] [           main] com.zaxxer.hikari.HikariConfig           : jdbcUrl.........................jdbc:postgresql://localhost:5432/postgres
2025-11-16T10:41:14.005-06:00 DEBUG 28284 --- [aws-rds-proxy] [           main] com.zaxxer.hikari.HikariConfig           : keepaliveTime...................120000
2025-11-16T10:41:14.005-06:00 DEBUG 28284 --- [aws-rds-proxy] [           main] com.zaxxer.hikari.HikariConfig           : leakDetectionThreshold..........0
2025-11-16T10:41:14.005-06:00 DEBUG 28284 --- [aws-rds-proxy] [           main] com.zaxxer.hikari.HikariConfig           : maxLifetime.....................1800000
2025-11-16T10:41:14.005-06:00 DEBUG 28284 --- [aws-rds-proxy] [           main] com.zaxxer.hikari.HikariConfig           : maximumPoolSize.................10
2025-11-16T10:41:14.005-06:00 DEBUG 28284 --- [aws-rds-proxy] [           main] com.zaxxer.hikari.HikariConfig           : metricRegistry..................none
2025-11-16T10:41:14.005-06:00 DEBUG 28284 --- [aws-rds-proxy] [           main] com.zaxxer.hikari.HikariConfig           : metricsTrackerFactory...........none
2025-11-16T10:41:14.006-06:00 DEBUG 28284 --- [aws-rds-proxy] [           main] com.zaxxer.hikari.HikariConfig           : minimumIdle.....................10
2025-11-16T10:41:14.006-06:00 DEBUG 28284 --- [aws-rds-proxy] [           main] com.zaxxer.hikari.HikariConfig           : password........................
2025-11-16T10:41:14.006-06:00 DEBUG 28284 --- [aws-rds-proxy] [           main] com.zaxxer.hikari.HikariConfig           : poolName........................"localHikariPool"
2025-11-16T10:41:14.006-06:00 DEBUG 28284 --- [aws-rds-proxy] [           main] com.zaxxer.hikari.HikariConfig           : readOnly........................false
2025-11-16T10:41:14.006-06:00 DEBUG 28284 --- [aws-rds-proxy] [           main] com.zaxxer.hikari.HikariConfig           : registerMbeans..................false
2025-11-16T10:41:14.006-06:00 DEBUG 28284 --- [aws-rds-proxy] [           main] com.zaxxer.hikari.HikariConfig           : scheduledExecutor...............none
2025-11-16T10:41:14.007-06:00 DEBUG 28284 --- [aws-rds-proxy] [           main] com.zaxxer.hikari.HikariConfig           : schema..........................none
2025-11-16T10:41:14.007-06:00 DEBUG 28284 --- [aws-rds-proxy] [           main] com.zaxxer.hikari.HikariConfig           : threadFactory...................internal
2025-11-16T10:41:14.007-06:00 DEBUG 28284 --- [aws-rds-proxy] [           main] com.zaxxer.hikari.HikariConfig           : transactionIsolation............default
2025-11-16T10:41:14.007-06:00 DEBUG 28284 --- [aws-rds-proxy] [           main] com.zaxxer.hikari.HikariConfig           : username........................"postgres"
2025-11-16T10:41:14.007-06:00 DEBUG 28284 --- [aws-rds-proxy] [           main] com.zaxxer.hikari.HikariConfig           : validationTimeout...............5000
2025-11-16T10:41:14.007-06:00  INFO 28284 --- [aws-rds-proxy] [           main] com.zaxxer.hikari.HikariDataSource       : localHikariPool - Starting...
2025-11-16T10:41:14.019-06:00 DEBUG 28284 --- [aws-rds-proxy] [           main] com.zaxxer.hikari.pool.PoolBase          : localHikariPool - Attempting to create/setup new connection (57dbbd2e-1c25-4030-96a1-e1a874eb40f6)
2025-11-16T10:41:14.209-06:00 DEBUG 28284 --- [aws-rds-proxy] [           main] com.zaxxer.hikari.pool.PoolBase          : localHikariPool - Established new connection (57dbbd2e-1c25-4030-96a1-e1a874eb40f6)
2025-11-16T10:41:14.212-06:00  INFO 28284 --- [aws-rds-proxy] [           main] com.zaxxer.hikari.pool.HikariPool        : localHikariPool - Added connection org.postgresql.jdbc.PgConnection@1ef31f71
2025-11-16T10:41:14.214-06:00  INFO 28284 --- [aws-rds-proxy] [           main] com.zaxxer.hikari.HikariDataSource       : localHikariPool - Start completed.
2025-11-16T10:41:14.276-06:00  INFO 28284 --- [aws-rds-proxy] [           main] org.hibernate.orm.connections.pooling    : HHH10001005: Database info:
	Database JDBC URL [Connecting through datasource 'HikariDataSource (localHikariPool)']
	Database driver: undefined/unknown
	Database version: 18.0
	Autocommit mode: undefined/unknown
	Isolation level: undefined/unknown
	Minimum pool size: undefined/unknown
	Maximum pool size: undefined/unknown
2025-11-16T10:41:14.326-06:00 DEBUG 28284 --- [aws-rds-proxy] [ool:housekeeper] com.zaxxer.hikari.pool.HikariPool        : localHikariPool - Pool stats (total=1/10, idle=1/10, active=0, waiting=0)
2025-11-16T10:41:14.326-06:00 DEBUG 28284 --- [aws-rds-proxy] [onnection-adder] com.zaxxer.hikari.pool.PoolBase          : localHikariPool - Attempting to create/setup new connection (df898777-2ad7-4c4e-8c71-bda140a0d554)
2025-11-16T10:41:14.369-06:00 DEBUG 28284 --- [aws-rds-proxy] [onnection-adder] com.zaxxer.hikari.pool.PoolBase          : localHikariPool - Established new connection (df898777-2ad7-4c4e-8c71-bda140a0d554)
2025-11-16T10:41:14.369-06:00 DEBUG 28284 --- [aws-rds-proxy] [onnection-adder] com.zaxxer.hikari.pool.HikariPool        : localHikariPool - Added connection org.postgresql.jdbc.PgConnection@506a1e6b
2025-11-16T10:41:14.405-06:00 DEBUG 28284 --- [aws-rds-proxy] [onnection-adder] com.zaxxer.hikari.pool.HikariPool        : localHikariPool - After adding stats (total=2/10, idle=2/10, active=0, waiting=0)
2025-11-16T10:41:14.405-06:00 DEBUG 28284 --- [aws-rds-proxy] [onnection-adder] com.zaxxer.hikari.pool.PoolBase          : localHikariPool - Attempting to create/setup new connection (4207c174-f34f-4e33-ab04-6f6583ede7dd)
2025-11-16T10:41:14.450-06:00 DEBUG 28284 --- [aws-rds-proxy] [onnection-adder] com.zaxxer.hikari.pool.PoolBase          : localHikariPool - Established new connection (4207c174-f34f-4e33-ab04-6f6583ede7dd)
2025-11-16T10:41:14.450-06:00 DEBUG 28284 --- [aws-rds-proxy] [onnection-adder] com.zaxxer.hikari.pool.HikariPool        : localHikariPool - Added connection org.postgresql.jdbc.PgConnection@5a92751b
2025-11-16T10:41:14.484-06:00 DEBUG 28284 --- [aws-rds-proxy] [onnection-adder] com.zaxxer.hikari.pool.HikariPool        : localHikariPool - After adding stats (total=3/10, idle=3/10, active=0, waiting=0)
2025-11-16T10:41:14.484-06:00 DEBUG 28284 --- [aws-rds-proxy] [onnection-adder] com.zaxxer.hikari.pool.PoolBase          : localHikariPool - Attempting to create/setup new connection (98a6acd5-2817-4746-b82c-45a06a3e1648)
2025-11-16T10:41:14.534-06:00 DEBUG 28284 --- [aws-rds-proxy] [onnection-adder] com.zaxxer.hikari.pool.PoolBase          : localHikariPool - Established new connection (98a6acd5-2817-4746-b82c-45a06a3e1648)
2025-11-16T10:41:14.535-06:00 DEBUG 28284 --- [aws-rds-proxy] [onnection-adder] com.zaxxer.hikari.pool.HikariPool        : localHikariPool - Added connection org.postgresql.jdbc.PgConnection@1f90e02d
2025-11-16T10:41:14.579-06:00 DEBUG 28284 --- [aws-rds-proxy] [onnection-adder] com.zaxxer.hikari.pool.HikariPool        : localHikariPool - After adding stats (total=4/10, idle=4/10, active=0, waiting=0)
2025-11-16T10:41:14.579-06:00 DEBUG 28284 --- [aws-rds-proxy] [onnection-adder] com.zaxxer.hikari.pool.PoolBase          : localHikariPool - Attempting to create/setup new connection (e780691b-c149-4578-9f88-3db964cb5eee)
2025-11-16T10:41:14.631-06:00 DEBUG 28284 --- [aws-rds-proxy] [onnection-adder] com.zaxxer.hikari.pool.PoolBase          : localHikariPool - Established new connection (e780691b-c149-4578-9f88-3db964cb5eee)
2025-11-16T10:41:14.631-06:00 DEBUG 28284 --- [aws-rds-proxy] [onnection-adder] com.zaxxer.hikari.pool.HikariPool        : localHikariPool - Added connection org.postgresql.jdbc.PgConnection@1f092cf2
2025-11-16T10:41:14.674-06:00 DEBUG 28284 --- [aws-rds-proxy] [onnection-adder] com.zaxxer.hikari.pool.HikariPool        : localHikariPool - After adding stats (total=5/10, idle=5/10, active=0, waiting=0)
2025-11-16T10:41:14.674-06:00 DEBUG 28284 --- [aws-rds-proxy] [onnection-adder] com.zaxxer.hikari.pool.PoolBase          : localHikariPool - Attempting to create/setup new connection (9f96f40f-de1d-41d1-8ce6-3f12cdbbbc24)
2025-11-16T10:41:14.722-06:00 DEBUG 28284 --- [aws-rds-proxy] [onnection-adder] com.zaxxer.hikari.pool.PoolBase          : localHikariPool - Established new connection (9f96f40f-de1d-41d1-8ce6-3f12cdbbbc24)
2025-11-16T10:41:14.722-06:00 DEBUG 28284 --- [aws-rds-proxy] [onnection-adder] com.zaxxer.hikari.pool.HikariPool        : localHikariPool - Added connection org.postgresql.jdbc.PgConnection@2e45985f
2025-11-16T10:41:14.753-06:00 DEBUG 28284 --- [aws-rds-proxy] [onnection-adder] com.zaxxer.hikari.pool.HikariPool        : localHikariPool - After adding stats (total=6/10, idle=6/10, active=0, waiting=0)
2025-11-16T10:41:14.753-06:00 DEBUG 28284 --- [aws-rds-proxy] [onnection-adder] com.zaxxer.hikari.pool.PoolBase          : localHikariPool - Attempting to create/setup new connection (d809e1fd-5f3e-4d22-82a3-0bbd0617623c)
2025-11-16T10:41:14.800-06:00 DEBUG 28284 --- [aws-rds-proxy] [onnection-adder] com.zaxxer.hikari.pool.PoolBase          : localHikariPool - Established new connection (d809e1fd-5f3e-4d22-82a3-0bbd0617623c)
2025-11-16T10:41:14.800-06:00 DEBUG 28284 --- [aws-rds-proxy] [onnection-adder] com.zaxxer.hikari.pool.HikariPool        : localHikariPool - Added connection org.postgresql.jdbc.PgConnection@67360a21
2025-11-16T10:41:14.845-06:00 DEBUG 28284 --- [aws-rds-proxy] [onnection-adder] com.zaxxer.hikari.pool.HikariPool        : localHikariPool - After adding stats (total=7/10, idle=7/10, active=0, waiting=0)
2025-11-16T10:41:14.845-06:00 DEBUG 28284 --- [aws-rds-proxy] [onnection-adder] com.zaxxer.hikari.pool.PoolBase          : localHikariPool - Attempting to create/setup new connection (9efc7614-6d51-43f2-90a3-215aea79dd21)
2025-11-16T10:41:14.889-06:00 DEBUG 28284 --- [aws-rds-proxy] [onnection-adder] com.zaxxer.hikari.pool.PoolBase          : localHikariPool - Established new connection (9efc7614-6d51-43f2-90a3-215aea79dd21)
2025-11-16T10:41:14.890-06:00 DEBUG 28284 --- [aws-rds-proxy] [onnection-adder] com.zaxxer.hikari.pool.HikariPool        : localHikariPool - Added connection org.postgresql.jdbc.PgConnection@7fbf1f62
2025-11-16T10:41:14.923-06:00 DEBUG 28284 --- [aws-rds-proxy] [onnection-adder] com.zaxxer.hikari.pool.HikariPool        : localHikariPool - After adding stats (total=8/10, idle=8/10, active=0, waiting=0)
2025-11-16T10:41:14.923-06:00 DEBUG 28284 --- [aws-rds-proxy] [onnection-adder] com.zaxxer.hikari.pool.PoolBase          : localHikariPool - Attempting to create/setup new connection (1c2b4c84-4b3a-4c13-aac8-09ffe33ae58d)
2025-11-16T10:41:14.961-06:00 DEBUG 28284 --- [aws-rds-proxy] [onnection-adder] com.zaxxer.hikari.pool.PoolBase          : localHikariPool - Established new connection (1c2b4c84-4b3a-4c13-aac8-09ffe33ae58d)
2025-11-16T10:41:14.961-06:00 DEBUG 28284 --- [aws-rds-proxy] [onnection-adder] com.zaxxer.hikari.pool.HikariPool        : localHikariPool - Added connection org.postgresql.jdbc.PgConnection@2907c2db
2025-11-16T10:41:14.978-06:00  INFO 28284 --- [aws-rds-proxy] [           main] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000489: No JTA platform available (set 'hibernate.transaction.jta.platform' to enable JTA platform integration)
2025-11-16T10:41:15.002-06:00 DEBUG 28284 --- [aws-rds-proxy] [onnection-adder] com.zaxxer.hikari.pool.HikariPool        : localHikariPool - After adding stats (total=9/10, idle=8/10, active=1, waiting=0)
2025-11-16T10:41:15.002-06:00 DEBUG 28284 --- [aws-rds-proxy] [onnection-adder] com.zaxxer.hikari.pool.PoolBase          : localHikariPool - Attempting to create/setup new connection (eda9d18f-20cc-4a0e-ab50-1a2666a463e7)
2025-11-16T10:41:15.036-06:00 DEBUG 28284 --- [aws-rds-proxy] [onnection-adder] com.zaxxer.hikari.pool.PoolBase          : localHikariPool - Established new connection (eda9d18f-20cc-4a0e-ab50-1a2666a463e7)
2025-11-16T10:41:15.036-06:00 DEBUG 28284 --- [aws-rds-proxy] [onnection-adder] com.zaxxer.hikari.pool.HikariPool        : localHikariPool - Added connection org.postgresql.jdbc.PgConnection@2b8230c4
2025-11-16T10:41:15.081-06:00 DEBUG 28284 --- [aws-rds-proxy] [onnection-adder] com.zaxxer.hikari.pool.HikariPool        : localHikariPool - After adding stats (total=10/10, idle=9/10, active=1, waiting=0)
2025-11-16T10:41:15.089-06:00 DEBUG 28284 --- [aws-rds-proxy] [           main] org.hibernate.SQL                        : 
    create table marydb.table_1 (
        id integer not null,
        name varchar(255),
        primary key (id)
    )
Hibernate: 
    create table marydb.table_1 (
        id integer not null,
        name varchar(255),
        primary key (id)
    )
2025-11-16T10:41:15.112-06:00  INFO 28284 --- [aws-rds-proxy] [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2025-11-16T10:41:15.256-06:00  INFO 28284 --- [aws-rds-proxy] [           main] o.j.z.d.a.AwsRdsProxyApplication         : Started AwsRdsProxyApplication in 2.688 seconds (process running for 2.967)
2025-11-16T10:41:15.262-06:00  INFO 28284 --- [aws-rds-proxy] [ionShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2025-11-16T10:41:15.265-06:00  INFO 28284 --- [aws-rds-proxy] [ionShutdownHook] com.zaxxer.hikari.HikariDataSource       : localHikariPool - Shutdown initiated...
2025-11-16T10:41:15.265-06:00 DEBUG 28284 --- [aws-rds-proxy] [ionShutdownHook] com.zaxxer.hikari.pool.HikariPool        : localHikariPool - Before shutdown stats (total=10/10, idle=10/10, active=0, waiting=0)
2025-11-16T10:41:15.266-06:00 DEBUG 28284 --- [aws-rds-proxy] [nnection-closer] com.zaxxer.hikari.pool.PoolBase          : localHikariPool - Closing connection org.postgresql.jdbc.PgConnection@1ef31f71: (connection evicted)
2025-11-16T10:41:15.267-06:00 DEBUG 28284 --- [aws-rds-proxy] [nnection-closer] com.zaxxer.hikari.pool.PoolBase          : localHikariPool - Closing connection org.postgresql.jdbc.PgConnection@506a1e6b: (connection evicted)
2025-11-16T10:41:15.267-06:00 DEBUG 28284 --- [aws-rds-proxy] [nnection-closer] com.zaxxer.hikari.pool.PoolBase          : localHikariPool - Closing connection org.postgresql.jdbc.PgConnection@5a92751b: (connection evicted)
2025-11-16T10:41:15.268-06:00 DEBUG 28284 --- [aws-rds-proxy] [nnection-closer] com.zaxxer.hikari.pool.PoolBase          : localHikariPool - Closing connection org.postgresql.jdbc.PgConnection@1f90e02d: (connection evicted)
2025-11-16T10:41:15.268-06:00 DEBUG 28284 --- [aws-rds-proxy] [nnection-closer] com.zaxxer.hikari.pool.PoolBase          : localHikariPool - Closing connection org.postgresql.jdbc.PgConnection@1f092cf2: (connection evicted)
2025-11-16T10:41:15.269-06:00 DEBUG 28284 --- [aws-rds-proxy] [nnection-closer] com.zaxxer.hikari.pool.PoolBase          : localHikariPool - Closing connection org.postgresql.jdbc.PgConnection@2e45985f: (connection evicted)
2025-11-16T10:41:15.269-06:00 DEBUG 28284 --- [aws-rds-proxy] [nnection-closer] com.zaxxer.hikari.pool.PoolBase          : localHikariPool - Closing connection org.postgresql.jdbc.PgConnection@67360a21: (connection evicted)
2025-11-16T10:41:15.269-06:00 DEBUG 28284 --- [aws-rds-proxy] [nnection-closer] com.zaxxer.hikari.pool.PoolBase          : localHikariPool - Closing connection org.postgresql.jdbc.PgConnection@7fbf1f62: (connection evicted)
2025-11-16T10:41:15.270-06:00 DEBUG 28284 --- [aws-rds-proxy] [nnection-closer] com.zaxxer.hikari.pool.PoolBase          : localHikariPool - Closing connection org.postgresql.jdbc.PgConnection@2907c2db: (connection evicted)
2025-11-16T10:41:15.270-06:00 DEBUG 28284 --- [aws-rds-proxy] [nnection-closer] com.zaxxer.hikari.pool.PoolBase          : localHikariPool - Closing connection org.postgresql.jdbc.PgConnection@2b8230c4: (connection evicted)
2025-11-16T10:41:15.271-06:00 DEBUG 28284 --- [aws-rds-proxy] [ionShutdownHook] com.zaxxer.hikari.pool.HikariPool        : localHikariPool - After  shutdown stats (total=0/10, idle=0/10, active=0, waiting=0)
2025-11-16T10:41:15.271-06:00  INFO 28284 --- [aws-rds-proxy] [ionShutdownHook] com.zaxxer.hikari.HikariDataSource       : localHikariPool - Shutdown completed.
  • Line 109-112: created a database table based on the @Entity.

6. AWS RDS Proxy Hikari Configuration

Most of the HikariCP configuration can use the default value, but the minimum-idle need to set to 0 and max-lifetime must be shorter than the Proxy’s Idle Client Connection Timeout.

Default Hikari Configuration

localHikariPool - configuration:
allowPoolSuspension.............false
autoCommit......................true
catalog.........................none
connectionInitSql...............none
connectionTestQuery.............none
connectionTimeout...............30000
credentials.....................com.zaxxer.hikari.util.Credentials@41f4039e
dataSource......................none
dataSourceClassName.............none
dataSourceJNDI..................none
dataSourceProperties............{password=}
driverClassName................."org.postgresql.Driver"
exceptionOverride...............none
exceptionOverrideClassName......none
healthCheckProperties...........{}
healthCheckRegistry.............none
idleTimeout.....................600000
initializationFailTimeout.......1
isolateInternalQueries..........false
jdbcUrl.........................jdbc:postgresql://localhost:5432/postgres
keepaliveTime...................120000
leakDetectionThreshold..........0
maxLifetime.....................1800000
maximumPoolSize.................10
metricRegistry..................none
metricsTrackerFactory...........none
minimumIdle.....................10
password........................
poolName........................"localHikariPool"
readOnly........................false
registerMbeans..................false
scheduledExecutor...............none
schema..........................none
threadFactory...................internal
transactionIsolation............default
username........................"postgres"
validationTimeout...............5000
  • Line 24: the max-life-time need to be shorter than the proxy’s “Idle Client Connection Timeout“. Otherwise, you will see the WARN message from HikariPool: “(This connection has been closed). Possibly consider a shorter maxLifeTime value“.
  • Line 28: the minimum-idle need to set to 0 as idle connection is not needed due to IAM auth token refreshes periodically.

7. Conclusion

In this example, I created a Spring Data JPA Java application that outlines the datasource and hikari configuration changes when connecting to the RDS proxy.

LayerAuthenticated ByManaged ByScopeCachesTime to LiveObjectiveReuse By
Spring App -> RDS ProxyIAM Auth TokenApplicationJVM/PODJDBC connection for queries via HikariCP poolMinutesReduce Application latencySame application
RDS Proxy -> DatabaseAWS Secrets ManagerAWS ServiceShared for clusterRead Database Sessions via AWS RDS ProxyHoursReduce Database LoadSame database user, name, session state, and auth method

8. Download

This was an example of a Java project that outlined both data source and hikari configuration changes when connecting to RDS Proxy.

Download
You can download the full source code of this example here: Spring Data JPA Switch to AWS RDS Proxy Example

Mary Zheng

Mary graduated from the Mechanical Engineering department at ShangHai JiaoTong University. She also holds a Master degree in Computer Science from Webster University. During her studies she has been involved with a large number of projects ranging from programming and software engineering. She worked as a lead Software Engineer where she led and worked with others to design, implement, and monitor the software solution.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Back to top button