Reputation: 3121
For my local dev environment, I use a .env file and then reference various variables like the DB connection in my Node.JS express application, e.g. process.env.DB_HOST
.
However, when I deploy my EB application I would like to check for the presence of an environment variable that is only defined in the EB console's environment variables. After defining it in the EB console, my node application is still unable to read it - if I console.log(process.env.MY_EB_CONSOLE_VARIABLE)
it is undefined.
How come? What's going on?
If it helps I have a dockerized node.js app I deploy to EB through the EB CLI.
Thanks
Upvotes: 1
Views: 1667
Reputation: 3121
Alright, so when you set environment variables on the elastic beanstalk console it will create a .env file. In your docker-compose.yml you will need to reference this .env file.
I expected the variables to simple be passed into my node process which is incorrect
In my docker-compose.yml I already had settings.env so I simply added the .env file like so:
# docker-compose.yml
version: "3.7"
services:
myApp:
build:
context: .
env_file:
- settings.env
- .env
ports:
- '80:3000'
Upvotes: 1