-->

Environment variables not available in Elastic Bea

2019-05-23 05:06发布

问题:

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.

回答1:

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).