How to use Spring profiles with SSM Parameter Store and Spring Cloud AWS 3.x

1k views Asked by At

I am trying to migrate AWS SSM Parameter Store integration of my Spring Boot app from Spring Boot 2.7.x with spring cloud aws 2.4.x to Spring Boot 3.1.x and spring cloud aws 3.0.2. At this moment I am not able to resolve parameter store values that contain Spring profiles as parameter path elements. E.g. SSM key /my-app/some-fixed-part-{spring-profile}/my-parameter.

With Spring Cloud 2.4.x I was able to provide the following configuration (YAML)

aws:
  paramstore:
    enabled: true
    prefix: /my-app
    name: some-fixed-part
    profile-separator: "-"

which allowed me to use ${my-parameter} within the app.

Following Spring Cloud 3.x approach to configure Parameter Store I ended up with:

spring:
  config:
    import: aws-parameterstore:/my-app/

Which resolves Parameter Store values (assuming active profile is dev) to some-fixed-part-dev.my-parameter instead of expected my-parameter.

The new configuration capabilities of Spring Cloud AWS 3.x do not allow to set name or profile-separator.

How would I need to set up Parameter Store integration to be able to use ${my-parameter} again? Thanks!

1

There are 1 answers

0
ldrag On

In the end it turned out to be quite easy as it's possible to inject active profile into the imported parameter store path.

spring:
  config:
    import: aws-parameterstore:/my-app/some-fixed-part-${spring.profiles.active}/

So no need to configure profile separator nor name.