Spring Boot with AWS parameter store

[this post originally published here on Oct 27, 2019]

In this post, there will be a demonstration of how to integrate AWS Parameter store with the spring boot application.

So instead of placing all application configuration properties into application.properties file, we’ll store everything in the AWS Parameter store.

First start a gradle java project will all required spring boot dependencies. Along with spring boot dependencies, spring provides cloud support for most of the major cloud platforms.

To use AWS parameter store, add the following dependency.

compile("org.springframework.cloud:spring-cloud-starter-aws-parameter-store-config:2.1.3.RELEASE")

build.gradle

The next step is to setup the parameter store related properties in the bootstrap.properties file.

bootstrap.properties

aws.paramstore.prefix=/config
aws.paramstore.name=tailone
aws.paramstore.enabled=true
aws.paramstore.profileSeparator=_

aws.paramstore.prefix and aws.paramstore.name used for construct the path of parameter in the store.

For example, if you want to retrieve parameter “db.username” from store, in this case prefix is /config and name is tailone. So you need to create the parameter as /config/tailone/db.username in the AWS console.

You can specify environment related properties in the same store and application configuration can be done by aws.paramstore.profileSeparator

[popup_anything id=”32″]

You can see in the image, if the active profile is prod, then you need to create parameter name with /config/tailone_prod/db.username in AWS and spring active profile value will be used for the environment.

Now, all the configuration is done and you want to use the value of db.username in the application. @value annotation can be used for autobinding these values in the program.

If you run this application without specifying any spring.profiles.active, then the value printed in the console will be the value stored with /config/tailone/db.username.

If the active profile is prod, then /config/tailone_prod/db.username value will be printed in the console.

You can refer this starter application in the following github link.

 https://github.com/ashoksl/java_samples/tree/master/bootawsstore

Published