11

I am trying to implement aws secret manager in java play framework. I followed the steps in this article https://www.geekyhacker.com/2020/05/09/getting-database-credentials-from-aws-secrets-manager-in-spring-boot/ to implement it in springboot first which worked perfectly.

Now, I am following the same steps in play framework.

Step 1: I added following dependencies in build.sbt

libraryDependencies ++= Seq(
  "com.amazonaws" % "aws-java-sdk" % "1.12.122",
  "com.amazonaws.secretsmanager" % "aws-secretsmanager-jdbc" % "1.0.6",
  "com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.12.2"
)

Other relevant dependencies includes:

libraryDependencies ++= Seq(
  "mysql" % "mysql-connector-java" % "8.0.21"
)
libraryDependencies ++= Seq(
  javaJpa,
  "org.hibernate" % "hibernate-core" % "5.4.21.Final", // it is JPA implementation
  "javax.validation" % "validation-api" % "2.0.1.Final" // added this because an issue was coming while running
)

Step 2: updated the conf file

Old config (which is working perfectly fine)

play.db {
  default = unclassified
}
base_db_url = "jdbc:mysql://{my_rds_endpoint}/"
db_annotations= "?createDatabaseIfNotExist=true"
base_db_user_name= "{rds_user_name}"
base_db_password= "{rds_password}"

db {
  unclassified.driver = com.mysql.cj.jdbc.Driver//com.mysql.cj.jdbc.Driver
  unclassified.jndiName = UnclassifiedDS
  unclassified.url= ${base_db_url}"unclassified_"${serverEnvironment}${db_annotations}
  unclassified.username=${base_db_user_name}
  unclassified.password=${base_db_password}
}

New config:

play.db {
      default = unclassified
    }
    base_db_url = "jdbc-secretsmanager:mysql://{my-rds-endpoint}/"
    db_annotations= "?createDatabaseIfNotExist=true"
    base_db_user_name= "{secret-name in secret manager}"
db {    
    unclassified.driver=com.amazonaws.secretsmanager.sql.AWSSecretsManagerMySQLDriver
    unclassified.jndiName = UnclassifiedDS
    unclassified.url= ${base_db_url}"unclassified_"${serverEnvironment}${db_annotations}
    unclassified.username=${base_db_user_name}
}

But getting the error: Configuration error [Cannot initialize to database] Caused by: java.lang.IllegalArgumentException: dataSource or dataSourceClassName or jdbcUrl is required.

Can anyone help me here?

Neel Kamal
  • 710
  • 2
  • 10
  • 27
  • 1
    I would look at using the recommended Java SDK which is AWS SDK for Java V2. See https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/javav2/example_code/secretsmanager – smac2020 Dec 03 '21 at 15:32
  • 1
    This example is for fetching secrets from the secret manager. It will need me to create a library that will fetch credentials from aws before establishing a database connection. I am looking for Secrets Manager JDBC which can do this work for me. – Neel Kamal Dec 05 '21 at 05:06

0 Answers0