friartuck
friartuck

Reputation: 3121

Setting Elastic Beanstalk environment variables in the console vs passing them from deployment

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

Answers (1)

friartuck
friartuck

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.

see https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_docker.container.console.html#docker-env-cfg.env-variables

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

Related Questions