aws/aws-secretsmanager-jdbc

Springboot - Exception encountered during context initialization

prafullazee opened this issue · 1 comments

Basic configuration, created a secret manager added RDS database details there, in springboot using dependencies

 <dependency>
      <groupId>com.amazonaws.secretsmanager</groupId>
      <artifactId>aws-secretsmanager-jdbc</artifactId>
      <version>2.0.0</version>
</dependency>
<dependency>
      <groupId>com.mysql</groupId>
      <artifactId>mysql-connector-j</artifactId>
      <version>8.2.0</version>
      </dependency>
<dependency>
	 <groupId>org.springframework.boot</groupId>
	 <artifactId>spring-boot-starter-data-jdbc</artifactId>
 </dependency>

Steps to reproduce the behavior:
Deployed in amazon aws ECS and got below stacktrace
`2023-12-07T12:15:08.189Z WARN 1 --- [ main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'configurationPropertiesBeans' defined in class path resource [org/springframework/cloud/autoconfigure/ConfigurationPropertiesRebinderAutoConfiguration.class]: Post-processing of merged bean definition failed
2023-12-07T12:15:08.477Z INFO 1 --- [ main] .s.b.a.l.ConditionEvaluationReportLogger :

Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2023-12-07T12:15:08.510Z ERROR 1 --- [ main] o.s.boot.SpringApplication : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'configurationPropertiesBeans' defined in class path resource [org/springframework/cloud/autoconfigure/ConfigurationPropertiesRebinderAutoConfiguration.class]: Post-processing of merged bean definition failed
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:575) `

If I am trying to access secret manager data through aws cli from the same ECS, I am able to access it with:

aws secretsmanager get-secret-value --secret-id secret-rds-details --region="ap-southeast-1"

With the same database credential, I am able to connect directly with below configuration:

spring.datasource.url=jdbc:mysql://${MYSQL_HOST:abcd.rds.amazonaws.com}:3306/database
spring.datasource.username=databaseuser
spring.datasource.password=databasepassword
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

I replaced this with

spring.datasource.driver-class-name=com.amazonaws.secretsmanager.sql.AWSSecretsManagerMySQLDriver
spring.datasource.url=jdbc-secretsmanager:mysql://${MYSQL_HOST:abcd.rds.amazonaws.com}:3306/database
spring.datasource.username=secret-rds-details
spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect

Expected behavior
It should be able to connect to RDS.

Environment:

Java version: 20
Springboot: 3.1.2

The issue was my ECS was not having access to the secret manager. so this is not a bug.