yogidilip
yogidilip

Reputation: 790

Spring boot not able to pull environment variable from AWS EC2

I have a EC2 environment variable defined. I can echo on the variable as echo $MY_ENV_VARIABLE and get the variable value printed in the console.

Now when I try to grab the same value from my Spring boot app, I am not able to do so. I have tried all the possibilities/features offered by spring boot. None of them seem to work.

So far I have tried:

@Value("#{systemEnvironment['MY_ENV_VARIABLE']}")

@Value("#{environment['MY_ENV_VARIABLE']}")

System.getenv("MY_ENV_VARIABLE")

I have tried "MY.ENV.VARIABLE" in all three places above as well.

What am I missing here? Why am I not able to grab the variable value in the code when it prints it fine in the echo.

Note: I do not have root access to the EC2 box to change any conf file.

Upvotes: 2

Views: 1114

Answers (1)

Antoniossss
Antoniossss

Reputation: 32507

@Value("${MY_ENV_VARIABLE}") Should work just fine.

However, if that System.getenv("MY_ENV_VARIABLE") does not work your you it means that such variable is not set in runtime env.

Double check if runtime user has such variable set.

Upvotes: 1

Related Questions