Search code examples
amazon-web-servicesspring-bootspring-cloudspring-cloud-configaws-secrets-manager

Importing secrets in Spring Boot application from AWS Secrets Manager


I stored my MySQL DB credentials in AWS secrets manager using the Credentials for other database option. I want to import these credentials in my application.properties file. Based on a few answers I found in this thread, I did the following:

  1. Added the dependency spring-cloud-starter-aws-secrets-manager-config
  2. Added spring.application.name = <application name> and spring.config.import = aws-secretsmanager: <Secret name> in application.properties
  3. Used secret keys as place holders in the following properties:
spring.datasource.url = jdbc:mysql://${host}:3306/db_name
spring.datasource.username=${username}
spring.datasource.password=${password}

I am getting the following error while running the application:

java.lang.IllegalStateException: Unable to load config data from 'aws-secretsmanager:<secret_name>'
Caused by: java.lang.IllegalStateException: File extension is not known to any PropertySourceLoader. If the location is meant to reference a directory, it must end in '/' or File.separator

First, is the process I am following correct? If yes, what is this error regarding and how to resolve this?


Solution

  • I found the problem that was causing the error. Apparently I was adding the wrong dependency.

    According to the latest docs, the configuration support for using spring.config.import to import AWS secrets has been moved to io.awspring.cloud from org.springframework.cloud. So the updated dependency would be io.awspring.cloud:spring-cloud-starter-aws-secrets-manager-config:2.3.3 and NOT org.springframework.cloud:spring-cloud-starter-aws-secrets-manager-config:2.2.6