0

Similar question was asked here, however the solution does not give the shell access to the same environment as the deployment. If I inspect os.environ from within the shell, none of the environment variables appear.

Is there a way to run the manage.py shell with the environment?

PS: As a little side question, I know the mantra for EBS is to stop using eb ssh, but then how would you run one-off management scripts (that you don't want to run on every deploy)?

Michał Zaborowski
  • 3,911
  • 2
  • 19
  • 39
Jad S
  • 2,705
  • 6
  • 29
  • 49

1 Answers1

0

One of the cases you have to run something once is db schema migrations. Usually you store information about that in the db... So you can use db to sync / ensure that something was triggered only once.

Personally I have nothing against using eb ssh, I see problems with it however. If you want to have CI/CD, that manual operation is against the rules.

Looks like you are referring to WWW/API part of Beanstalk. If you need something that is quite frequent... maybe worker is more suitable? Problem here is that if API goes deployed first you would have wrong schema.

In general you are using EC2, so it's user data stores information that spins up you service. So there you can put your "stuff". Still you need to sync / ensure. Here are docs for beanstalk - for more information how to do that.

Edit

Beanstalk is kind of instrumentation on top of EC2. So there must be a way to work with it, since you have access to user data of that EC2s. No worries you don't need to dig that deep. There is good way of instrumenting your server. It is called ebextensions. It can be used to put files on the server, trigger commands, instrument cron. What ever you want.

You can create ebextension, with container_commands this time Python Configuration Namespaces section. That commands are executed on each deployment. Still, problem is that you need to sync since more then one deployment can go at the same time. Good part is that you can set env in the way you want.

I have no problem to access to the environment variables. How did you get the problem? Try do prepare page with the map.

Community
  • 1
  • 1
Michał Zaborowski
  • 3,911
  • 2
  • 19
  • 39
  • could you give more clarification on the last part, and how one can retrieve the environment variables from within `eb ssh`? – Jad S Dec 09 '17 at 19:31
  • 1
    a one-off case that comes to mind is if I want to run a script that manipulates the DB data using the django ORM e.g. I added a column to a table and want to run a script that goes through the list of objects in that table and populates the columns for entries already in there (maybe inferred from another column) – Jad S Dec 09 '17 at 19:33