zivchen
zivchen

Reputation: 49

How to setup multiple environments (dev\stage\production) with elastic beanstalk?

I need to do the following

Change environment variables according to the published env. Set Set up cron jobs according to the dev. I I would like to run just 1 command line "eb deploy dev" or something similar.

Upvotes: 4

Views: 2760

Answers (2)

zivchen
zivchen

Reputation: 49

This is my solution to the problem, it took some time to setup but now i can do all the changes with 1 command line.

Make your own folder with all the files for all the environments. In .ebextensions folder setup empty config files for eb. npm runs a script named "deploy.js" together with the flag of the specific env. The script will do the following

  • copy the requested env data to the empty files according to the env
  • git stash the changes of .ebextensions folder (eb deploys using git)
  • eb use env
  • eb deploy

So now i can tun npm run deploy:dev and everything runs

Upvotes: 0

Samuel Fekete
Samuel Fekete

Reputation: 324

Use setenv

You can set environment variables with setenv. These will then be remembered for that environment.

More details: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb3-setenv.html

Example

For example, suppose you have created an EB environment called 'staging' and you want to set the variable DB to 'localhost', you can use: eb setenv DB=localhost -e staging

Crons

Now that you have a different environment variables, you can check them in a script etc. to decide if the cron should be set up.

Note that the crons may not actually have access to your environment variables so you need to set those again for the cron while setting up the cron.

Upvotes: 1

Related Questions