3

I'm attempting to configure my elastic beanstalk java application using environment variables via the Procfile like so:

web: ./bin/myservice -Dhttp.port=$PORT

The PORT environment variable is set via the AWS ui in the "Software Configuration" screen of my beanstalk environment.

However, the logs are indicating that $PORT is not being interpolated:

Exception in thread "main" java.lang.ExceptionInInitializerError
    at com.whatever.services.myservice.Main.main(Main.scala)
Caused by: java.lang.NumberFormatException: For input string: "$PORT"
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    at java.lang.Integer.parseInt(Integer.java:569)

What is the correct way to pass options to my application?

Edit 1: This seems to be an issue related to the sbt native packager plugin which I use to create a distributable zip archive of the project. The bin/myservice file it generates is interpreting $PORT literally and passing that to the application.

novon
  • 973
  • 3
  • 15
  • 30

1 Answers1

3

Try removing -Dhttp.port=$PORT from Procfile.

In the ui in "Software Configuration" try setting the variable JAVA_OPTS to -Dhttp.port=9000 (replace 9000 with whatever port your nginx proxy is using -- 5000 is the default I believe).

enter image description here

Dave Maple
  • 8,102
  • 4
  • 45
  • 64
  • I'm not seeing a "JVM Command line options" in the beanstalk UI. – novon Jan 09 '17 at 01:45
  • are you using the Java SE container type @novon? http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/java-se-platform.html – Dave Maple Jan 09 '17 at 01:45
  • Yep thats what I selected. – novon Jan 09 '17 at 01:49
  • Sorry -- this used to be an option -- it still appears in my older applications. I just spun up a new environment and it's no longer there. Looking to see what the new method is. – Dave Maple Jan 09 '17 at 01:53
  • ah -- ok. you can set this with Software Configuration but try this key => val: JAVA_OPTS: "-Dhttp.port=9000" (replace 9000 with whatever value). LMK if this works and I'll update the answer to reflect the latest mechanism. – Dave Maple Jan 09 '17 at 02:01
  • *snip* I spoke too soon, that seems to have worked as long as the application.ini file generated by sbt native packager is removed. Thanks so much for the help! – novon Jan 09 '17 at 02:50
  • Will setup a test with activator – Dave Maple Jan 09 '17 at 02:54
  • No need @dave-maple that does work, I needed to reupload my application package without the application.ini. I updated my previous comment. – novon Jan 09 '17 at 02:55
  • Ok great. Can you accept if the answer looks right so others can find? – Dave Maple Jan 09 '17 at 02:56
  • Running into this too, so on the SE container beanstalk image, JAVA_OPTS is some how automatically ingested by the JVM? – danieljimenez Feb 15 '17 at 03:48