I have a REST service built with Spring Boot where I'm using an application.yml
file to set up environment variables. The REST service will be deployed to Amazon Elastic Beanstalk. I have set up Environment Properties
in the configuration for the Environment (Configuration -> Software Configuration -> Environment Properties
)
I would like for the REST service to pick up the environment variables from AWS Environment Properties when they are available and then use environment variables specified in the application.yml
file when the Environment Properties are not available as a fallback.
spring:
profiles: default
datasource:
type: org.mariadb.jdbc.MariaDbDataSource
driverClassName: org.mariadb.jdbc.Driver
url: jdbc:mariadb://localhost:3306/someDB
username: someUserName
password: somePassword
What I'm trying to achieve is that I wouldn't have to change the profile used in application.yml
when I deploy on AWS or do development locally.
I've tried this which doesn't work
spring:
profiles: aws
datasource:
type: org.mariadb.jdbc.MariaDbDataSource
driverClassName: org.mariadb.jdbc.Driver
url: ${ADDRESS_FOR_RDS:jdbc:mariadb://localhost:3306/someDB}
username: ${USERNAME:someUserName}
password: ${PASSWORD:somePassword}
Trying to specify as ${AWS_PROPERTY_NAME:FALLBACK_OPTION}
as per this Stack Overflow answer.
I have been able to get this working using Spring profiles, per this Stack Overflow question.