in java spring-boot aws ~ read.

Deploying Spring-Boot to Amazon Elastic Beanstalk

While there are a ton of guides on how to use spring boot, I was not able to find anything about how to deploy different configurations on Amazon's Elastic Beanstalk. Here is a how to on some of the options you have when deploying to Elastic Beanstalk. It does not matter if you are deploying via a jar or war the configuration methods are essentially the same.

The first thing we had to ensure is that we could override the configuration. This way we can provide settings specific to any one deployment. Spring-boot offers many ways to do this. There are several options for externalized configuration.

Using Spring Application JSON

The first option I looked into was using SPRING_APPLICATION_JSON to configure the properties for the installation. While this does work, there are several limitations when deploying to Elastic Beanstalk.

The first lesson I learned is that you can not set this value in the user interface. You can see my report here on stack overflow: You can get this configuration to work using an .ebextensions folder and configuration in your jar/war.

Here is an example configuration file.

Don't forget to have gradle insert this into your war/jar file!

We ended up not going with this idea. The configuration JSON would up getting rather complex as we expand the config options with in our application.

Using Spring Profiles

Enter spring boot profiles. This is exactly the feature you should be using for this type of deployment.

Profiles allow you to provide a set of default settings, then override any settings you need to for a given environment. This is essentially the same as using the JSON config, but lets you have these settings in a config file not a JSON string.

The profile setting can be provided in Elastic Beanstalk's UI without any issues. Here is our production profile being loaded into the JVM:

You can also load this via a system property called SPRING_PROFILES_ACTIVE.

To override any of your default settings just provide the profile specific value in that profile's configuration file. When using the default settings this is application-${profileName}.properties.

Things to watch for!

Be sure your default configuration is not setting this will override your provided profiles. If you want to ensure a given profile is also being loaded use spring.profiles.include.