spring-cloud-aws
spring-cloud-aws copied to clipboard
Parameter Store path requires trailing slash
I created some parameters in parameter store with a "/dev/appname" prefix, e.g. "/dev/appname/spring.datasource.url". I configured the spring.config.import
property via an environment variable. As per the documentation, I did not include a trailing slash.
SPRING_CONFIG_IMPORT=aws-parameterstore:/dev/appname
Looking at the debug log, I saw that a leading period "." was added to the property name, e.g.
2024-02-20T09:37:54.470+11:00 DEBUG 33036 --- [ main] i.a.c.p.ParameterStorePropertySource : Populating property retrieved from AWS Parameter Store: .spring.datasource.url
This meant that my app wouldn't start because it couldn't connect to the database, since the "spring.datasource.url" was not populated. This behaviour makes sense looking at the ParameterStorePropertySource
code in the getParameters
method, which removes the path "/dev/appname" leaving "/spring.datasource.url", then replaces all remaining slashes with periods, i.e. ".spring.datasource.url".
Changing the path to include a trailing slash, i.e. "aws-parameterstore:/dev/appname/" resolved the problem, and the correct "spring.datasource.url" property was populated. To prevent others experiencing this problem in the future, I think that either
- the examples in the documentation should be updated to specify a trailing slash in the parameter path, or
- the code should be updated to strip any leading slashes after the path is removed.
I'm happy to submit a PR if that helps.
I am using spring-cloud-aws-starter-parameter-store 3.1.0.