Broonix
Broonix

Reputation: 1155

Spring-boot Amazon Elastic Beanstalk ignores 'SPRING_APPLICATION_JSON'

I've tried with both jar and war versions of my app, but no matter what I do SPRING_APPLICATION_JSON is ignored when deployed on Elastic Beanstalk. When testing locally using the same jar this works.

export SPRING_APPLICATION_JSON='{"server": { "port": 5000 } }'
java -jar my-app-1.0.1-SNAPSHOT.jar

... snip useless output
2016-07-05 12:18:02.877  INFO 10654 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 5000 (http)
2016-07-05 12:18:02.886  INFO 10654 --- [           main] com.me.app.MyApplication      : Started MyApplication in 22.827 seconds (JVM running for 23.514)

When setting the same JSON on AWS in Elastic Beanstalk (jar version shown)

enter image description here

But when the app launches with in AWS. The logs show it is not seeing the updated configuration value for server.port

2016-07-05 15:58:33.511  INFO 2267 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2016-07-05 15:58:33.520  INFO 2267 --- [           main] com.me.app.MyApplication      : Started MyApplication in 37.746 seconds (JVM running for 47.043)

Why does this work locally but not on Elastic Beanstalk?

Upvotes: 3

Views: 1123

Answers (2)

Goatfryed
Goatfryed

Reputation: 183

Since eb meddles with the json format, passing the json as base64 worked out best for me.

I'm using a Procfile like this

web: SPRING_APPLICATION_JSON=$(echo SPRING_APPLICATION_JSON_BASE64 | base64 --decode) java $JAVA_OPTS -jar app.jar $JAVA_ARGS

and configured the env var SPRING_APPLICATION_JSON_BASE64 with my base64 encoded json string.

This works nice if .ebextensions isn't an option, because you have frequently changing config values independent of version control or require it to pass secrets in it like i did.

Upvotes: 0

Broonix
Broonix

Reputation: 1155

So after some reading and testing. It turns out this is a bug in the Elastic Beanstalk user-interface. Any property that requires quote will not work. This the same as How to config Meteor on AWS/EBS using METEOR_SETTINGS environment variable

I did work around the issue using .ebextensions. Which properly lets you insert escaped values.

option_settings:
  - option_name: SPRING_APPLICATION_JSON
    value: {"server":{"port": 5000}}

Upvotes: 2

Related Questions