Allen Y
Allen Y

Reputation: 690

How to set specific env config vars after heroku ps:exec?

I'm using heroku ps:exec to get into a dyno. I'd like to run a command, but the command relies on some env config vars that are already set on the application.

Per Heroku's documentation:

The SSH session created by Heroku Exec doesn’t have the config vars set as environment variables (i.e., env in a session doesn’t list config vars set by heroku config:set).

How can you get around this? Is it possible to activate specific env vars from the production configuration after you're already in exec mode? I am using Python.

Here's a similar SO post, but the only submitted answer doesn't seem to work with a Python project.

Upvotes: 0

Views: 44

Answers (1)

Chris
Chris

Reputation: 136982

heroku exec logs into a running dyno using SSH. As you noted, these sessions don't have access to config vars by design.

But this isn't the only way to run commands on Heroku. Most of the time, heroku run is a better choice. This creates a one-off dyno that gets discarded when the command finishes running. One-off dynos do have access to your applications's config vars.

The only time I'd reach for heroku exec over heroku run is when I need to access the dyno's local state. Applications run best on Heroku when local state is minimal and dynos can be spun up or down at any time.

Upvotes: -1

Related Questions