1

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)

enter image description here

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.

M. Justin
  • 14,487
  • 7
  • 91
  • 130
g3blv
  • 3,877
  • 7
  • 38
  • 51
  • is **url: ${ADDRESS_FOR_RDS:jdbc:mariadb://localhost:3306/someDB}** what you really have in the configuration file or is it copy/paste mistake? – TheOni Jan 01 '18 at 10:34
  • @TheOni That is what I really have, trying to use `ADDRESS_FOR_RDS` as the Property name for the value setup in the Environment Properties on aws EB and `jdbc:mariadb://localhost:3306/someDB` as the fallback. – g3blv Jan 01 '18 at 10:37

0 Answers0