从 AWS Secrets Manager 导入 Spring Boot 应用程序中的密钥

Mah*_*ary 7 amazon-web-services spring-boot spring-cloud spring-cloud-config aws-secrets-manager

我使用该选项将 MySQL 数据库凭证存储在 AWS Secret Manager 中Credentials for other database。我想将这些凭据导入到我的application.properties文件中。根据我在该线程中找到的一些答案,我执行了以下操作:

  1. 添加了依赖spring-cloud-starter-aws-secrets-manager-config
  2. 添加spring.application.name = <application name>spring.config.import = aws-secretsmanager: <Secret name>application.properties
  3. 使用密钥作为以下属性中的占位符:
spring.datasource.url = jdbc:mysql://${host}:3306/db_name
spring.datasource.username=${username}
spring.datasource.password=${password}
Run Code Online (Sandbox Code Playgroud)

我在运行应用程序时收到以下错误:

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
Run Code Online (Sandbox Code Playgroud)

首先,我遵循的流程正确吗?如果是,此错误与什么有关以及如何解决?

Mah*_*ary 12

我发现了导致错误的问题。显然我添加了错误的依赖项。

根据最新的文档,用于导入 AWS 密钥的配置支持spring.config.import已从. 所以更新的依赖关系将是而不是io.awspring.cloudorg.springframework.cloudio.awspring.cloud:spring-cloud-starter-aws-secrets-manager-config:2.3.3 org.springframework.cloud:spring-cloud-starter-aws-secrets-manager-config:2.2.6